From 9af6a42649d5ea5607177ecc5a41109374aed721 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 2 Aug 2023 14:33:43 +0100 Subject: [PATCH] fix: drop error using nextset() in pipeline mode 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 | 13 ------------- tests/test_pipeline.py | 13 +++---------- tests/test_pipeline_async.py | 13 +++---------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 515acc573..7b8395c6c 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -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 diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 77c3c6f7c..2de7fabb3 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -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() == [] diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index c578618fd..b20c1de7f 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -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()) == [] -- 2.47.2