From: Mike Bayer Date: Fri, 21 Dec 2007 16:44:12 +0000 (+0000) Subject: added assertion for expiry's current inability to detect a PK switch in the DB X-Git-Tag: rel_0_4_2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=75d7d8d5105cbdeb9d3bfcccc7b7f08e217f2f7f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added assertion for expiry's current inability to detect a PK switch in the DB --- diff --git a/test/orm/naturalpks.py b/test/orm/naturalpks.py index 069aea0b35..2a8bead05e 100644 --- a/test/orm/naturalpks.py +++ b/test/orm/naturalpks.py @@ -51,6 +51,32 @@ class NaturalPKTest(ORMTest): sess.clear() u1 = sess.query(User).get('ed') self.assertEquals(User(username='ed', fullname='jack'), u1) + + def test_expiry(self): + mapper(User, users) + + sess = create_session() + u1 = User(username='jack', fullname='jack') + + sess.save(u1) + sess.flush() + assert sess.get(User, 'jack') is u1 + + users.update(values={u1.c.username:'jack'}).execute(username='ed') + + try: + # expire/refresh works off of primary key. the PK is gone + # in this case so theres no way to look it up. criterion- + # based session invalidation could solve this [ticket:911] + sess.expire(u1) + u1.username + assert False + except exceptions.InvalidRequestError, e: + assert "Could not refresh instance" in str(e) + + sess.clear() + assert sess.get(User, 'jack') is None + assert sess.get(User, 'ed').fullname == 'jack' @testing.unsupported('sqlite','mysql') def test_onetomany_passive(self):