[Grok-dev] separate ZODB databse

Flavio Coelho fccoelho at gmail.com
Wed Nov 21 14:56:41 EST 2007


Hi,

this question is probably not suited for a developers mailing list,
but since I could not find a grok-users list here it go:

I need to access data in a separate ZODB database from a grok
application.

(Yes, I am one of those crazy people that like to use ZODB by
itself...)

So... I already have a database. it is accessible through a module
(e.g: db.py) that define the persistent classes which are the base of
the objects that are stored in the db.

Since I populated this database from the aforementioned module db.py,
all instances in the db are instances of __main__.Myclass, where
Myclass is a class, derived from Presistent, defined on db.py.

My problem is that if I try to import db.py from another module (from
db import *) which is not itself executed directly, I get broken
instances since there is no __main__:

<persistent broken __main__.Myclass instance
'\x00\x00\x00\x00\x00\x07\xd0C'>

app.py in a grok application, is imported, not executed.

to be more clear here is an example:

if I run the following script:

from db import *
from pprint import pprint

u= zroot['userdb']['fccoelho']
pprint(u)
print u.userid

i get the following output:
<db.User object at 0x8f45d6c>
fccoelho

but if I run the same code by importing it from a shell for instance,
I get this:

<persistent broken __main__.User instance
'\x00\x00\x00\x00\x00\x07\xd0C'>
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'>



I need to find a way around this problem, so any suggestion will be
greatly appreciated.

Thanks,

Flávio


More information about the Grok-dev mailing list