From: Denis Laxalde Date: Mon, 4 Apr 2022 15:19:55 +0000 (+0200) Subject: fix: only request a pipeline flush in returning executemany() X-Git-Tag: 3.1~122^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e49aa7a72616f87436e92e7266861164fdfc1864;p=thirdparty%2Fpsycopg.git fix: only request a pipeline flush in returning executemany() A full Sync is not needed as we're only interested in getting results when returning=True. --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 8a473a987..459351581 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -241,7 +241,7 @@ class BaseCursor(Generic[ConnectionType, Row]): self._last_query = query if returning: - yield from pipeline._exit_gen() + yield from pipeline._fetch_gen(flush=True) for cmd in self._conn._prepared.get_maintenance_commands(): yield from self._conn._exec_command(cmd) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 7dba9ec7b..aba1f9b04 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -278,7 +278,7 @@ def test_executemany_trace_returning(conn, trace): roundtrips = [k for k, g in groupby(items, key=attrgetter("direction"))] assert roundtrips == ["F", "B"] * 3 assert items[-2].direction == "F" # last 2 items are F B - assert len([i for i in items if i.type == "Sync"]) == 3 + assert len([i for i in items if i.type == "Sync"]) == 1 def test_prepared(conn): diff --git a/tests/test_pipeline_async.py b/tests/test_pipeline_async.py index afee1e6de..269af39e6 100644 --- a/tests/test_pipeline_async.py +++ b/tests/test_pipeline_async.py @@ -281,7 +281,7 @@ async def test_executemany_trace_returning(aconn, trace): roundtrips = [k for k, g in groupby(items, key=attrgetter("direction"))] assert roundtrips == ["F", "B"] * 3 assert items[-2].direction == "F" # last 2 items are F B - assert len([i for i in items if i.type == "Sync"]) == 3 + assert len([i for i in items if i.type == "Sync"]) == 1 async def test_prepared(aconn):