[Grok-dev] separate ZODB databse

Leonardo Rochael Almeida leorochael at gmail.com
Tue Jan 8 17:46:53 EST 2008


As answered on grok-br when this message was originally sent, a quick
workaround is to set the classes into "sys.modules['__main__']",
before attempting to load them.

On Nov 21, 2007 5:56 PM, Flavio Coelho <fccoelho at gmail.com> wrote:
> 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
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>


More information about the Grok-dev mailing list