From: Denis Laxalde Date: Wed, 6 Oct 2021 11:37:43 +0000 (+0200) Subject: Raise NotSupportedError when using a server-side cursor in pipeline mode X-Git-Tag: 3.1~146^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a406ffa3809bb2ee930700073ebbad7e727c8c54;p=thirdparty%2Fpsycopg.git Raise NotSupportedError when using a server-side cursor in pipeline mode --- diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 2ac01c953..8439ecea1 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -249,6 +249,10 @@ class ServerCursor(Cursor[Row]): """ if kwargs: raise TypeError(f"keyword not supported: {list(kwargs)[0]}") + if self._pgconn.pipeline_status: + raise e.NotSupportedError( + "server-side cursors not supported in pipeline mode" + ) try: with self._conn.lock: @@ -370,6 +374,11 @@ class AsyncServerCursor(AsyncCursor[Row]): ) -> _AC: if kwargs: raise TypeError(f"keyword not supported: {list(kwargs)[0]}") + if self._pgconn.pipeline_status: + raise e.NotSupportedError( + "server-side cursors not supported in pipeline mode" + ) + try: async with self._conn.lock: await self._conn.wait( diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 7546f5b2b..31662dd76 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -23,3 +23,9 @@ def test_cursor_stream(conn): with conn.pipeline(), conn.cursor() as cur: with pytest.raises(psycopg.ProgrammingError): cur.stream("select 1").__next__() + + +def test_server_cursor(conn): + with conn.cursor(name="pipeline") as cur, conn.pipeline(): + with pytest.raises(psycopg.NotSupportedError): + cur.execute("select 1") diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index aa9a739e7..3aa6b2e59 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -26,3 +26,9 @@ async def test_cursor_stream(aconn): async with aconn.pipeline(), aconn.cursor() as cur: with pytest.raises(psycopg.ProgrammingError): await cur.stream("select 1").__anext__() + + +async def test_server_cursor(aconn): + async with aconn.cursor(name="pipeline") as cur, aconn.pipeline(): + with pytest.raises(psycopg.NotSupportedError): + await cur.execute("select 1")