]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Don't clear the cursor state after closing
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 30 Jul 2021 19:14:58 +0000 (21:14 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 30 Jul 2021 19:14:58 +0000 (21:14 +0200)
It might be still useful to access the cursor state (e.g. rowcount, the
status message) after the cursor is closed, especially if the block
syntax is used.

Memory use is not really a problem: memory is cleared on GC anyway and
most functions using a cursor don't rely on the memory freed between
close() and the end of the function.

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

index c9c1fae25238b490ca91f0ebfe6e7897e03e18f2..860521368bd63df62fc01efe236cefaea1ae2771 100644 (file)
@@ -462,11 +462,6 @@ class BaseCursor(Generic[ConnectionType, Row]):
 
     def _close(self) -> None:
         self._closed = True
-        # however keep the query available, which can be useful for debugging
-        # in case of errors
-        pgq = self._pgq
-        self._reset()
-        self._pgq = pgq
 
 
 AnyCursor = BaseCursor[Any, Row]
index c008a530c9f755976da2475b7a721dbe8021906b..b88080292ec059a9435b52fad315fd41248ac09f 100644 (file)
@@ -50,7 +50,7 @@ def test_status(conn):
     cur.execute("select 1")
     assert cur.status == cur.ExecStatus.TUPLES_OK
     cur.close()
-    assert cur.status is None
+    assert cur.status == cur.ExecStatus.TUPLES_OK
 
 
 def test_execute_many_results(conn):
@@ -241,7 +241,7 @@ def test_rowcount(conn):
     assert cur.rowcount == 42
 
     cur.close()
-    assert cur.rowcount == -1
+    assert cur.rowcount == 42
 
 
 def test_rownumber(conn):
index f4f35c38ad123b73275562031cee193c663494a4..1e0ec046d90096671949c41c9cd7547e0f060682 100644 (file)
@@ -50,7 +50,7 @@ async def test_status(aconn):
     await cur.execute("select 1")
     assert cur.status == cur.ExecStatus.TUPLES_OK
     await cur.close()
-    assert cur.status is None
+    assert cur.status == cur.ExecStatus.TUPLES_OK
 
 
 async def test_execute_many_results(aconn):
@@ -243,7 +243,7 @@ async def test_rowcount(aconn):
     assert cur.rowcount == 42
 
     await cur.close()
-    assert cur.rowcount == -1
+    assert cur.rowcount == 42
 
 
 async def test_rownumber(aconn):