On 9/16/15 5:49 PM, Jonathan Vanasco wrote:
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'
OK, what's great here is (in keeping with bugs are always reported in
twos, no matter how long theyve been around) that someone just hit this
yesterday:
https://groups.google.com/forum/#!topic/sqlalchemy/Q3pSYzjL3mE
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.
yes, the relationship is being added twice, declarative is doing it
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.
this should definitely be caught under #2. should be easy. I've
worked this out in
https://bitbucket.org/zzzeek/sqlalchemy/issues/3532/detect-property-being-assigned-to-more.
--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.