Add this test case to LazyTest in test/orm/lazytest1.py
def test_lazy_backref(self):
class Information(object):
pass
class Relation(object):
pass
session = create_session()
mapper(Relation, rel_table)
mapper(Information, info_table, properties={
'rels': relation(Relation, backref="info")
})
info = session.query(Information).get(1)
session.expunge(info)
rel = Relation()
rel.info = info # FAILS!!
session.save(rel) # NEVER GOT HERE...
Test result using SA r1712:
======================================================================
ERROR: test_lazy_backref (__main__.LazyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/orm/lazytest1.py", line 106, in test_lazy_backref
rel.info = info
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/attributes.py", line 26, in __set__
self.set(None, obj, value)
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/attributes.py", line 190, in set
ext.set(event or self, obj, value, old)
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/attributes.py", line 444, in set
getattr(child.__class__, self.key).append(event, child, obj)
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/attributes.py", line 222, in append
self.get(obj).append_with_event(value, event)
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/attributes.py", line 137, in get
l = InstrumentedList(self, obj, self._adapt_list(callable_()),
init=False)
File "/Users/dmiller/Code/PyOE/resources/lib/SQLAlchemy/lib/
sqlalchemy/orm/properties.py", line 370, in lazyload
raise exceptions.InvalidRequestError("Parent instance %s is not
bound to a Session; lazy load operation of attribute '%s' cannot
proceed" % (instance.__class__, self.key))
InvalidRequestError: Parent instance <class '__main__.Information'>
is not bound to a Session; lazy load operation of attribute 'rels'
cannot proceed
----------------------------------------------------------------------
It seems unintuitive that I can't set the rel.info attribute with a
disconnected Information instance even though they are both (i.e. rel
and info) disconnected from the session. Ideally it would not throw
an exception even on session.save(rel). Is this by design?
~ Daniel
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users