]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: make no-tuple results available after executemany returning
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Mar 2022 12:29:11 +0000 (14:29 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Apr 2022 23:23:22 +0000 (01:23 +0200)
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.

psycopg/psycopg/cursor.py
tests/test_cursor.py
tests/test_cursor_async.py

index b123e7b5e80eed5ac5867f27b2df37d0bcddfaff..7433ccb51a4e24599932c48aab9deabfd2d4e7b6 100644 (file)
@@ -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)
index b32a8fc9c429a7d8d4c6201e2b235d8847ee4a04..dad1324281b3b3433888ddf88370d2a22b519f9f 100644 (file)
@@ -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
 
 
index 20faea1db27e6743a9ead8b340ac96f6c2e79d39..e372715a3f8962044aa6c6b604d788267cbc6a20 100644 (file)
@@ -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