diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-05-08 02:21:57 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-08 12:57:21 -0400 |
| commit | c99fc44e170be61696206872701ff75e4c8a3711 (patch) | |
| tree | 6bd437739570339483d591ce48158ef2a5465214 /test/orm | |
| parent | 65b3f4aaa072438006f90033a413f10b911ba717 (diff) | |
| download | sqlalchemy-c99fc44e170be61696206872701ff75e4c8a3711.tar.gz | |
Use the "committed" values when extracting many-to-one lazyload value
The scalar object set() method calls upon the lazy loader
to get at the "old" value of the attriute, however doesn't
ensure that the "committed" value of the foreign key attributes
is used. If the user has manipulated these attributes and they
themselves have pending, non committed changes, we get the
"new" value which these attributes would have set up if they
were flushed. "old" vs "new" value is always about how the
value has changed since the load, so we always have to use the
DB-persisted values for everything when looking for "old".
Change-Id: I82bdc40ad0cf033c3a98f3361776cf3161542cd6
Fixes: #3708
Diffstat (limited to 'test/orm')
| -rw-r--r-- | test/orm/test_load_on_fks.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/test/orm/test_load_on_fks.py b/test/orm/test_load_on_fks.py index 471c8665a..efb709ff2 100644 --- a/test/orm/test_load_on_fks.py +++ b/test/orm/test_load_on_fks.py @@ -97,7 +97,7 @@ class LoadOnFKsTest(AssertsExecutionResults, fixtures.TestBase): sess.rollback() Base.metadata.drop_all(engine) - def test_load_on_pending_disallows_backref_event(self): + def test_load_on_pending_allows_backref_event(self): Child.parent.property.load_on_pending = True sess.autoflush = False c3 = Child() @@ -105,23 +105,30 @@ class LoadOnFKsTest(AssertsExecutionResults, fixtures.TestBase): c3.parent_id = p1.id c3.parent = p1 - # a side effect of load-on-pending with no autoflush. - # a change to the backref event handler to check - # collection membership before assuming "old == new so return" - # would fix this - but this is wasteful and autoflush - # should be turned on. - assert c3 not in p1.children + # backref fired off when c3.parent was set, + # because the "old" value was None. + # change as of [ticket:3708] + assert c3 in p1.children - def test_enable_rel_loading_disallows_backref_event(self): + def test_enable_rel_loading_allows_backref_event(self): sess.autoflush = False c3 = Child() sess.enable_relationship_loading(c3) c3.parent_id = p1.id c3.parent = p1 - # c3.parent is already acting like a "load" here, - # so backref events don't work - assert c3 not in p1.children + # backref fired off when c3.parent was set, + # because the "old" value was None + # change as of [ticket:3708] + assert c3 in p1.children + + def test_m2o_history_on_persistent_allows_backref_event(self): + c3 = Child() + sess.add(c3) + c3.parent_id = p1.id + c3.parent = p1 + + assert c3 in p1.children def test_load_on_persistent_allows_backref_event(self): Child.parent.property.load_on_pending = True @@ -132,15 +139,16 @@ class LoadOnFKsTest(AssertsExecutionResults, fixtures.TestBase): assert c3 in p1.children - def test_enable_rel_loading_on_persistent_disallows_backref_event(self): + def test_enable_rel_loading_on_persistent_allows_backref_event(self): c3 = Child() sess.enable_relationship_loading(c3) c3.parent_id = p1.id c3.parent = p1 - # c3.parent is already acting like a "load" here, - # so backref events don't work - assert c3 not in p1.children + # backref fired off when c3.parent was set, + # because the "old" value was None + # change as of [ticket:3708] + assert c3 in p1.children def test_no_load_on_pending_allows_backref_event(self): # users who stick with the program and don't use |
