From: Daniele Varrazzo Date: Tue, 29 Mar 2022 12:29:11 +0000 (+0200) Subject: fix: make no-tuple results available after executemany returning X-Git-Tag: 3.1~145^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4982d4a096d2fb03b01b49ddd531ab91f5538e1;p=thirdparty%2Fpsycopg.git fix: make no-tuple results available after executemany returning There could be useful info there, if the user asks for it. Now this doesn't slow down the happy execute path, because the default of returning is False. --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index b123e7b5e..7433ccb51 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -266,7 +266,7 @@ class BaseCursor(Generic[ConnectionType, Row]): results = yield from self._maybe_prepare_gen(pgq, prepare=True) assert results is not None self._check_results(results) - if returning and results[0].status == ExecStatus.TUPLES_OK: + if returning: self._results.extend(results) for res in results: @@ -526,7 +526,7 @@ class BaseCursor(Generic[ConnectionType, Row]): else: # Received from executemany() - if self._execmany_returning and results[0].status == ExecStatus.TUPLES_OK: + if self._execmany_returning: self._results.extend(results) if first_batch: self._set_current_result(0) diff --git a/tests/test_cursor.py b/tests/test_cursor.py index b32a8fc9c..dad132428 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -316,8 +316,13 @@ def test_executemany_no_result(conn, execmany): returning=True, ) assert cur.rowcount == 2 + assert cur.statusmessage.startswith("INSERT") with pytest.raises(psycopg.ProgrammingError): cur.fetchone() + pgresult = cur.pgresult + assert cur.nextset() + assert cur.statusmessage.startswith("INSERT") + assert pgresult is not cur.pgresult assert cur.nextset() is None diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 20faea1db..e372715a3 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -304,8 +304,13 @@ async def test_executemany_no_result(aconn, execmany): returning=True, ) assert cur.rowcount == 2 + assert cur.statusmessage.startswith("INSERT") with pytest.raises(psycopg.ProgrammingError): await cur.fetchone() + pgresult = cur.pgresult + assert cur.nextset() + assert cur.statusmessage.startswith("INSERT") + assert pgresult is not cur.pgresult assert cur.nextset() is None