]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: don't fail assert if fetching without result in pipeline mode
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 01:44:26 +0000 (03:44 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:23:22 +0000 (01:23 +0200)
The error can be triggered easily by the user. The condition is handled
just naturally by all the methods calling _fetch_pipeline().

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

index 6f5a96e0e53eb05cfaa13915886337d652f4ce17..ee77166929595135e086cf94f90dc6cb7314cc3c 100644 (file)
@@ -847,4 +847,3 @@ class Cursor(BaseCursor["Connection[Any]", Row]):
         ):
             with self._conn.lock:
                 self._conn.wait(self._conn._pipeline._fetch_gen(flush=True))
-            assert self.pgresult
index 3bf1004d52ab5abc6729a76205ff41ce55be94e4..8c4ac4d9e66b269727dc9d427e9b5a57f8420dcd 100644 (file)
@@ -195,4 +195,3 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         ):
             async with self._conn.lock:
                 await self._conn.wait(self._conn._pipeline._fetch_gen(flush=True))
-            assert self.pgresult
index 2b4abe53f462d0288efcc3bb40c9a6f7540e97c3..d87556a3c809d61e3c59c807b7b66d8937ece64b 100644 (file)
@@ -194,6 +194,13 @@ def test_pipeline_commit_aborted(conn):
             conn.commit()
 
 
+def test_fetch_no_result(conn):
+    with conn.pipeline():
+        cur = conn.cursor()
+        with pytest.raises(e.ProgrammingError):
+            cur.fetchone()
+
+
 def test_executemany(conn):
     conn.autocommit = True
     conn.execute("drop table if exists execmanypipeline")
index f24cc144f4f2cbae4bf08000ac3b462d30af5882..b2a0fd22c3c48dd9e5016b416e0aed17d0054dc6 100644 (file)
@@ -197,6 +197,13 @@ async def test_pipeline_commit_aborted(aconn):
             await aconn.commit()
 
 
+async def test_fetch_no_result(aconn):
+    async with aconn.pipeline():
+        cur = aconn.cursor()
+        with pytest.raises(e.ProgrammingError):
+            await cur.fetchone()
+
+
 async def test_executemany(aconn):
     await aconn.set_autocommit(True)
     await aconn.execute("drop table if exists execmanypipeline")