I'm converting a mid-size project from webware's middlekit to sqlobject.
One problem that I've run out of workarounds for is an import issue,
similar to one that was last discussed on the mailing list in September.
I'm storing all of my SQLObject classes in a single module called
booking. At the top of files that use the classes, I include the line
from stuff import *
This seems to work fine, except occasionally, when I get
File "/sandbox/Main/eventleaf.py", line 1, in ?
from stuff import *
File "/usr/lib/python2.2/ihooks.py", line 397, in import_module
q, tail = self.find_head_package(parent, name)
File "/usr/lib/python2.2/ihooks.py", line 433, in find_head_package
q = self.import_it(head, qname, parent)
File "/usr/lib/python2.2/ihooks.py", line 486, in import_it
m = self.loader.load_module(fqname, stuff)
File "./WebKit/ImportSpy.py", line 30, in load_module
File "/usr/lib/python2.2/ihooks.py", line 270, in load_module
m = self.hooks.load_source(name, filename, file)
File "/usr/lib/python2.2/ihooks.py", line 168, in load_source
return imp.load_source(name, filename, file)
File "/sandbox/Main/stuff.py", line 5, in ?
class Person(SQLObject):
File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line 151, in __new__
assert not classRegistry.get(registry, {}).has_key(className), "A database object by the name %s has already been created" % repr(className)
AssertionError: A database object by the name 'Person' has already been created
I'm not changing the definition, just importing the SQLObj classes into
a module that is imported by a module that has already imported the
SQLObj classes.
This seems intermittent, and I have not yet tracked down the situation
that makes it happen, but I suspect it may only be happening to modules
loaded via this code:
res = imp.find_module(req + "leaf")
mod = imp.load_module(req + "leaf", res[0], res[1], res[2])
This may be a red herring, but it's starting to smell like the cause.
Could someone who understands python and sqlobject internals better than
I do help me solve this puzzle?
- Scott
|