From: Mike Bayer Date: Wed, 11 Mar 2020 14:41:12 +0000 (-0400) Subject: Repair broken call to sys.exc_info() X-Git-Tag: rel_1_4_0b1~474 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ceba13d4be5e73fed4522d6f66ab4c54f60fd983;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Repair broken call to sys.exc_info() Fixed regression in 1.3.14 due to :ticket:`4849` where a sys.exc_info() call failed to be invoked correctly when a flush error would occur. Test coverage has been added for this exception case. Fixes: #5196 Change-Id: Ib59a58a3a9d4c9c6f4b751201b794816a9f70225 --- diff --git a/doc/build/changelog/unreleased_13/5196.rst b/doc/build/changelog/unreleased_13/5196.rst new file mode 100644 index 0000000000..3183164a74 --- /dev/null +++ b/doc/build/changelog/unreleased_13/5196.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: orm, bug + :tickets: 5196 + + Fixed regression in 1.3.14 due to :ticket:`4849` where a sys.exc_info() + call failed to be invoked correctly when a flush error would occur. Test + coverage has been added for this exception case. + diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index b542f05065..f172649ba2 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1661,7 +1661,7 @@ class Session(_SessionClassMethods): "consider using a session.no_autoflush block if this " "flush is occurring prematurely" ) - util.raise_(e, with_traceback=sys.exc_info[2]) + util.raise_(e, with_traceback=sys.exc_info()[2]) def refresh( self, diff --git a/test/orm/test_session.py b/test/orm/test_session.py index a2f0a9aa19..fa68fedfe1 100644 --- a/test/orm/test_session.py +++ b/test/orm/test_session.py @@ -449,6 +449,29 @@ class SessionStateTest(_fixtures.FixtureTest): is_true(sess.autoflush) + def test_autoflush_exception_addition(self): + User, users = self.classes.User, self.tables.users + Address, addresses = self.classes.Address, self.tables.addresses + mapper(User, users, properties={"addresses": relationship(Address)}) + mapper(Address, addresses) + + s = Session(testing.db) + + u1 = User(name="first") + + s.add(u1) + s.commit() + + u1.addresses.append(Address(email=None)) + + # will raise for null email address + assert_raises_message( + sa.exc.DBAPIError, + ".*raised as a result of Query-invoked autoflush; consider using " + "a session.no_autoflush block.*", + s.query(User).first, + ) + def test_deleted_flag(self): users, User = self.tables.users, self.classes.User