]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Repair broken call to sys.exc_info()
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2020 14:41:12 +0000 (10:41 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2020 14:44:48 +0000 (10:44 -0400)
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

doc/build/changelog/unreleased_13/5196.rst [new file with mode: 0644]
lib/sqlalchemy/orm/session.py
test/orm/test_session.py

diff --git a/doc/build/changelog/unreleased_13/5196.rst b/doc/build/changelog/unreleased_13/5196.rst
new file mode 100644 (file)
index 0000000..3183164
--- /dev/null
@@ -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.
+
index b542f05065c64c32922c69ff007d360bdbb061af..f172649ba2c0aa371f2e475fa63f8da11b262e1d 100644 (file)
@@ -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,
index a2f0a9aa1931fba0b2ae4a2e913efcfc96f556b8..fa68fedfe1ce1257080a1e11bd8218b5e68d1bec 100644 (file)
@@ -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