From: Mike Bayer Date: Fri, 29 Aug 2014 18:23:36 +0000 (-0400) Subject: - add a test to events within load to verify something we want X-Git-Tag: rel_0_9_8~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8c8b22e4742d5750dca808c3350e39c6a3e26f07;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add a test to events within load to verify something we want to ensure stays the same on 1.0 --- diff --git a/test/orm/test_events.py b/test/orm/test_events.py index f7667b9f1d..8410dee51f 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -964,6 +964,47 @@ class RefreshTest(_fixtures.FixtureTest): sess.query(User).first() eq_(canary, []) + def test_changes_reset(self): + """test the contract of load/refresh such that history is reset. + + This has never been an official contract but we are testing it + here to ensure it is maintained given the loading performance + enhancements. + + """ + User = self.classes.User + + @event.listens_for(User, "load") + def canary1(obj, context): + obj.name = 'new name!' + + @event.listens_for(User, "refresh") + def canary2(obj, context, props): + obj.name = 'refreshed name!' + + sess = Session() + u1 = User(name='u1') + sess.add(u1) + sess.commit() + sess.close() + + u1 = sess.query(User).first() + eq_( + attributes.get_history(u1, "name"), + ((), ['new name!'], ()) + ) + assert "name" not in attributes.instance_state(u1).committed_state + assert u1 not in sess.dirty + + sess.expire(u1) + u1.id + eq_( + attributes.get_history(u1, "name"), + ((), ['refreshed name!'], ()) + ) + assert "name" not in attributes.instance_state(u1).committed_state + assert u1 in sess.dirty + def test_repeated_rows(self): User = self.classes.User