diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-03-10 17:51:35 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-03-10 17:51:35 -0400 |
| commit | 66fa5b50a53ebe234f19e23b7dfa6ff310969996 (patch) | |
| tree | 674ac8497eb469114ceef25d0709ef47def227da /test/orm/test_session.py | |
| parent | 95e53d0b6072510c7a687e3bcc92246d9b3d7181 (diff) | |
| download | sqlalchemy-66fa5b50a53ebe234f19e23b7dfa6ff310969996.tar.gz | |
- Fixed bug where the session attachment error "object is already
attached to session X" would fail to prevent the object from
also being attached to the new session, in the case that execution
continued after the error raise occurred.
fixes #3301
Diffstat (limited to 'test/orm/test_session.py')
| -rw-r--r-- | test/orm/test_session.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/orm/test_session.py b/test/orm/test_session.py index 2aa0cd3eb..58551d763 100644 --- a/test/orm/test_session.py +++ b/test/orm/test_session.py @@ -505,6 +505,25 @@ class SessionStateTest(_fixtures.FixtureTest): assert user not in s assert s.query(User).count() == 0 + def test_already_attached(self): + User = self.classes.User + users = self.tables.users + mapper(User, users) + + s1 = Session() + s2 = Session() + + u1 = User(id=1, name='u1') + make_transient_to_detached(u1) # shorthand for actually persisting it + s1.add(u1) + + assert_raises_message( + sa.exc.InvalidRequestError, + "Object '<User.*?>' is already attached to session", + s2.add, u1 + ) + assert u1 not in s2 + assert not s2.identity_map.keys() @testing.uses_deprecated() def test_identity_conflict(self): @@ -562,7 +581,7 @@ class SessionStateTest(_fixtures.FixtureTest): assert u2 is not None and u2 is not u1 assert u2 in sess - assert_raises(Exception, lambda: sess.add(u1)) + assert_raises(AssertionError, lambda: sess.add(u1)) sess.expunge(u2) assert u2 not in sess |
