This drove me crazy for an hour today, until I finally figured out what was
going on.
I have a class with a few relationships:
class Foo(base):
# relationships have a prefix that describe the relation l_
(list) or o_ (scalar)
l_Bars = relationship("Bars")
o_Biz = relationship("Biz", uselist=False)
I'm linking together a few APIs and needed to make the relationships
accessible under another name:
class Foo(base):
l_Bars = relationship("Bars")
the_bars = l_Bars
When committing a session, SqlAlchemy raises an error and is incredibly
unhappy.
Under 1.8 the error is:
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/state.py", line
429, in _expire
[impl.key for impl in self.manager._scalar_loader_impls
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/util/langhelpers.py",
line 747, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File
"build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/instrumentation.py", line
111, in _scalar_loader_impls
self.values() if attr.impl.accepts_scalar_loader])
AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'
The error was different on earlier versions. (I think I tested on .9.9 and
1.0.6)
The .9.9 error is :
... intel.egg/sqlalchemy/orm/state.py", line 394, in _expire if
impl.accepts_scalar_loader and \
AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'
Once I figured out what caused it/ what is going on -- this makes perfect
sense, and I could just use a class property to proxy the relationship
under a different name.
However I think there may be a docs deficiency or bug involved:
1. I couldn't find anything in the docs that said "Don't do this!" in terms
of duplicating a class relationship
2. This seems to be an uncaught error/edge-case.
- `attr.impl` is None , yet was allowed to progress this far into the
orm logic without getting caught.
- I'm not sure if anything could have been done to alert me "YOU ARE
DOING SOMETHING WRONG/STUPID" in this error, but I'm actually amazed I was
able to pinpoint this error during a test-run. Based on the error message,
a dozen other things from the checkin should/could have caused this.
And just to be clear -- by "bug" I mean that SqlAlchemy doesn't seem to be
correctly catching or reporting this User Error.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.