From: Daniele Varrazzo Date: Sat, 2 Apr 2022 01:44:26 +0000 (+0200) Subject: fix: don't fail assert if fetching without result in pipeline mode X-Git-Tag: 3.1~145^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aebd497f225988dc37fa4de397306dbf6c2efd1;p=thirdparty%2Fpsycopg.git fix: don't fail assert if fetching without result in pipeline mode The error can be triggered easily by the user. The condition is handled just naturally by all the methods calling _fetch_pipeline(). --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 6f5a96e0e..ee7716692 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -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 diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 3bf1004d5..8c4ac4d9e 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -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 diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 2b4abe53f..d87556a3c 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -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") diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index f24cc144f..b2a0fd22c 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -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")