[ZODB-Dev] Can't use invokeFactory method in non-FileStorage folder

zhimin at iss.nus.edu.sg zhimin at iss.nus.edu.sg
Thu Jun 26 04:54:34 EDT 2003


Hello,

I have a Plone site in Data.fs FileStorage, and mounted one BDB storage
folder under the Plone site folder using DBTab (see dbtab.conf below). I
wrote an external method  (see testAddLink.py below) to programmatically
create Link object inside the BDB folder with invokeFactory method.
testAddLink is run from testInvokeFactory.py (see below) which has proxy
role=Manager to get pass the authentication. The Plone site is at
/PloneSite, while the BDB folder is at /PloneSite/bdb.

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):
  Module ZPublisher.Publish, line 98, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 39, in call_object
  Module Shared.DC.Scripts.Bindings, line 252, in __call__
  Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 315, in _exec
  Module Script (Python), line 1, in testInvokeFactory   - <PythonScript at
/testInvokeFactory>   - Line 1
  Module Products.ExternalMethod.ExternalMethod, line 231, in __call__   -
__traceback_info__: ((), {}, None)
  Module C:\Program Files\Zope\Extensions\testAddLink.py, line 37, in
testAddLink
  Module C:\Program Files\Zope\Extensions\testAddLink.py, line 81, in
listContentTypes
  Module C:\Program Files\Zope\Extensions\testAddLink.py, line 88, in
getPortalTypesTool
  Module Products.CMFCore.utils, line 97, in getToolByName
AttributeError: portal_types


However, if I change in Try Block 2, the line:
db = configuration.getDatabase(name='BDB')
    to
db = configuration.getDatabase(name='Main')
, then Try Block 2 will run without exception.


Why is it so? Is the change I made above the correct way? Or is there other
solution?

Thanks,
Zhi Min



------------     my sys      ---------------------------------
Zope = (Zope 2.6.1 (binary release, python 2.1, win32-x86), python 2.1.3,
win32)
ZEO = 2.0.1b
CMF = 1.3
Plone = 1.0.1



-------------    dbtab.conf     ---------------------------------
[Storage: Main]
type=ClientStorage
addr=zeo://localhost:9001
storage=main

[Database: Main]
cache_size=4000
mount_paths=/

[Storage: BDB]
type=ClientStorage
addr=zeo://localhost:9001
storage=bdb

[Database: BDB]
cache_size=4000
mount_paths=/PloneSite/bdb
container_class=Products.CMFPlone.PloneFolder.PloneFolder
open_at_startup=1



-------------     testAddLink.py    external method
-----------------------------------
def testAddLink(self):
    from Products.DBTab.MainConfiguration import configuration

    # Try Block 1
    try:
        db = configuration.getDatabase(name='Main')
        conn = db.open()
        root = conn.root()
        storage_folder = getattr(root['Application'], 'PloneSite', None)
        storage_folder = getattr(storage_folder, 'Members', None)
        storage_folder.invokeFactory(id='123', type_name='Link')
        get_transaction().commit()
    finally:
        conn.close()


    # 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()


-------------     testInvokeFactory.py     script
-----------------------------------
return context.testAddLink()





More information about the ZODB-Dev mailing list