]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: drop error using nextset() in pipeline mode 614/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 2 Aug 2023 13:33:43 +0000 (14:33 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 2 Aug 2023 15:15:41 +0000 (16:15 +0100)
Now that the behaviour of pipeline is the same of non-pipeline, raising
an exception on nextset is a difference in behaviour we can probably
drop.

psycopg/psycopg/cursor.py
tests/test_pipeline.py
tests/test_pipeline_async.py

index 515acc57351400e8809c36e1bb2e554f5570350c..7b8395c6cde0a8cb08f9d64501f55c21cc169e05 100644 (file)
@@ -156,19 +156,6 @@ class BaseCursor(Generic[ConnectionType, Row]):
         Return `!True` if a new result is available, which will be the one
         methods `!fetch*()` will operate on.
         """
-        # Python 3.1 would accumulate execute() results in the cursor, but it
-        # was an undesired difference with non-pipeline mode, so it was
-        # deprecated in 3.1.10; in 3.2 we moved to clobber previous execute()
-        # results and, because running multiple statements in the same
-        # execute() is not supported in pipeline mode, there is no reason to
-        # support nextset(). This error replaces the previous warning.
-        if self._execmany_returning is None and self._conn._pipeline:
-            raise e.NotSupportedError(
-                "using nextset() in pipeline mode for several execute() is"
-                " not supported. Please use several cursors to receive more"
-                " than one result"
-            )
-
         if self._iresult < len(self._results) - 1:
             self._select_current_result(self._iresult + 1)
             return True
index 77c3c6f7ce3c957cdcadeb5fe82ea845f13dacbc..2de7fabb3ff2deafafb1af33d0c0c63324380019 100644 (file)
@@ -595,19 +595,12 @@ def test_concurrency(conn):
     assert after > before
 
 
-def test_execute_nextset_error(conn):
+def test_execute_nextset(conn):
     cur = conn.cursor()
-    cur.execute("select 1")
-    cur.execute("select 2")
-
-    assert cur.fetchall() == [(2,)]
-    assert not cur.nextset()
-    assert cur.fetchall() == []
-
     with conn.pipeline():
         cur.execute("select 1")
         cur.execute("select 2")
 
         assert cur.fetchall() == [(2,)]
-        with pytest.raises(psycopg.NotSupportedError, match="nextset"):
-            assert cur.nextset()
+        assert not cur.nextset()
+        assert cur.fetchall() == []
index c578618fd7b188f3de3e6b9962a47a5105686785..b20c1de7f40f224a388a691eed7fba339a15fb4a 100644 (file)
@@ -603,19 +603,12 @@ async def test_concurrency(aconn):
     assert after > before
 
 
-async def test_execute_nextset_error(aconn):
+async def test_execute_nextset(aconn):
     cur = aconn.cursor()
-    await cur.execute("select 1")
-    await cur.execute("select 2")
-
-    assert (await cur.fetchall()) == [(2,)]
-    assert not cur.nextset()
-    assert (await cur.fetchall()) == []
-
     async with aconn.pipeline():
         await cur.execute("select 1")
         await cur.execute("select 2")
 
         assert (await cur.fetchall()) == [(2,)]
-        with pytest.raises(psycopg.NotSupportedError, match="nextset"):
-            assert cur.nextset()
+        assert not cur.nextset()
+        assert (await cur.fetchall()) == []