[ZODB-Dev] Can't use invokeFactory method in non-FileStorage
folder
Dieter Maurer
dieter at handshake.de
Fri Jun 27 02:07:56 EDT 2003
zhimin at iss.nus.edu.sg wrote at 2003-6-26 03:54 +0800:
> ...
> The invokeFactory() can create Link (and other Plone objects) in
> /PloneSite/Members (see Try Block 1 in testAddLink.py), but generate an
> exception shown below when invokeFactory() is run to create Link in
> /PloneSite/bdb (see Try Block 2 in testAddLink.py) :
>
> ...
> Traceback (innermost last):
> ...
> getPortalTypesTool
> Module Products.CMFCore.utils, line 97, in getToolByName
> AttributeError: portal_types
> ...
> # Try Block 2
> try:
> db = configuration.getDatabase(name='BDB')
> conn = db.open()
> root = conn.root()
> storage_folder = getattr(root['Application'], 'PloneSite', None)
> storage_folder = getattr(storage_folder, 'bdb', None)
> storage_folder.invokeFactory(id='789', type_name='Link')
> get_transaction().commit()
> finally:
> conn.close()
"getToolByName" uses acquisition to find the portal.
In your "bdb" case, the acquisition context ends at the mount point
and therefore below the portal.
Your solution is too sophisticated.
You need (and should) not open a connection explicitely but rely on
Zope doing it automatically during normal traversal/attribute lookup.
Opening a database connection is for exceptional cases only...
Dieter
More information about the ZODB-Dev
mailing list