]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix!: only keep results of last execute() by a cursor in pipeline mode
authorDenis Laxalde <denis.laxalde@dalibo.com>
Mon, 31 Jul 2023 14:13:58 +0000 (16:13 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 2 Aug 2023 13:41:10 +0000 (14:41 +0100)
The assertion on fetchall() in 'test_execute_nextset_error' now passes.

Fixes #604.

docs/news.rst
psycopg/psycopg/cursor.py

index e3e4b09e306a13f40e53f7d11cdb7cdf994adc76..9567483b0b586802c815f1263ee32c15c0675b79 100644 (file)
@@ -18,6 +18,8 @@ Psycopg 3.2 (unreleased)
 - Disable receiving more than one result on the same cursor in pipeline mode,
   to iterate through `~Cursor.nextset()`. The behaviour was different than
   in non-pipeline mode and not totally reliable (:ticket:`#604`).
+  The `Cursor` now only preserves the results set of the last
+  `~Cursor.execute()`, consistently with non-pipeline mode.
 
 
 Psycopg 3.1.10 (unreleased)
index 356e94018eb3aad99a70835944a984a0fb4706a2..515acc57351400e8809c36e1bb2e554f5570350c 100644 (file)
@@ -529,17 +529,15 @@ class BaseCursor(Generic[ConnectionType, Row]):
         self._make_row = self._make_row_maker()
 
     def _set_results(self, results: List["PGresult"]) -> None:
-        first_batch = not self._results
-
         if self._execmany_returning is None:
             # Received from execute()
-            self._results.extend(results)
-            if first_batch:
-                self._select_current_result(0)
+            self._results[:] = results
+            self._select_current_result(0)
 
         else:
             # Received from executemany()
             if self._execmany_returning:
+                first_batch = not self._results
                 self._results.extend(results)
                 if first_batch:
                     self._select_current_result(0)