]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
"graceful fetch" test should....clean up gracefully!
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 26 Nov 2021 23:43:23 +0000 (18:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 26 Nov 2021 23:49:34 +0000 (18:49 -0500)
this test was relying on gc to close out the connection.
this would lead to problems with aiosqlite as we invalidate
async connetions that aren't gracefully closed, and this test
suite was create tables per suite, so we'd get into a spot where
a new sqlite memory connection without the tables would get set up.

would only occur for full test run + -n2 + C extensions + python 3.7,
but we assume that is all related to just getting gc to trigger
or not trigger at exactly the right moment in this situation.

confirmed if we add a gc.collect() to the test without explcitly
closing out the conenction, the connection is gc'ed and detached,
and we get the error reproduced on the subsequent test.

Change-Id: Icc9d4bc703f0842c27600f532f34bc4c7d3baf21

test/sql/test_resultset.py

index c5dd35ce15bf84c952b5004a218535643b1f3e1c..4aa932b471a455c06dcd8d7cd44571119f7aae83 100644 (file)
@@ -775,31 +775,31 @@ class CursorResultTest(fixtures.TablesTest):
 
         users = self.tables.users
 
-        conn = testing.db.connect()
-        keys_lambda = lambda r: r.keys()  # noqa: E731
-
-        for meth in [
-            lambda r: r.fetchone(),
-            lambda r: r.fetchall(),
-            lambda r: r.first(),
-            lambda r: r.scalar(),
-            lambda r: r.fetchmany(),
-            lambda r: r._getter("user"),
-            keys_lambda,
-            lambda r: r.columns("user"),
-            lambda r: r.cursor_strategy.fetchone(r, r.cursor),
-        ]:
-            trans = conn.begin()
-            result = conn.execute(users.insert(), dict(user_id=1))
-
-            assert_raises_message(
-                exc.ResourceClosedError,
-                "This result object does not return rows. "
-                "It has been closed automatically.",
-                meth,
-                result,
-            )
-            trans.rollback()
+        with testing.db.connect() as conn:
+            keys_lambda = lambda r: r.keys()  # noqa: E731
+
+            for meth in [
+                lambda r: r.fetchone(),
+                lambda r: r.fetchall(),
+                lambda r: r.first(),
+                lambda r: r.scalar(),
+                lambda r: r.fetchmany(),
+                lambda r: r._getter("user"),
+                keys_lambda,
+                lambda r: r.columns("user"),
+                lambda r: r.cursor_strategy.fetchone(r, r.cursor),
+            ]:
+                trans = conn.begin()
+                result = conn.execute(users.insert(), dict(user_id=1))
+
+                assert_raises_message(
+                    exc.ResourceClosedError,
+                    "This result object does not return rows. "
+                    "It has been closed automatically.",
+                    meth,
+                    result,
+                )
+                trans.rollback()
 
     def test_fetchone_til_end(self, connection):
         result = connection.exec_driver_sql("select * from users")