]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Raise NotSupportedError when using a server-side cursor in pipeline mode
authorDenis Laxalde <denis.laxalde@dalibo.com>
Wed, 6 Oct 2021 11:37:43 +0000 (13:37 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:17:57 +0000 (01:17 +0200)
psycopg/psycopg/server_cursor.py
tests/test_pipeline.py
tests/test_pipeline_async.py

index 2ac01c953b76a3a5387275a323c355867ef727e9..8439ecea182f17c32afc5b7430865269f51af485 100644 (file)
@@ -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(
index 7546f5b2b2aed0418619e2642ea023ef8a7e8386..31662dd76c259895467b26592e621db6c3562208 100644 (file)
@@ -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")
index aa9a739e7b9117d944fa411be13d195446c3dbb0..3aa6b2e59c7a88809f758dd8fc83c1608160140f 100644 (file)
@@ -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")