]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fixed cursor close check + updated news
authorSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 15:08:27 +0000 (20:38 +0530)
committerSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 15:08:27 +0000 (20:38 +0530)
.gitignore
docs/news.rst
psycopg/psycopg/server_cursor.py
tests/test_server_cursor.py

index cf12ee0e5aae58292045f199b4d1f7ffa93852e9..2554231eb89349625a372f16148f89f37d609db9 100644 (file)
@@ -11,3 +11,4 @@ __pycache__/
 *.html
 /psycopg_binary/
 .vscode
+.venv
\ No newline at end of file
index cc467eb8d878df81df2ea20ce5513437b516249c..767227881bf65513166acf48e7d500f55151f281 100644 (file)
@@ -9,11 +9,6 @@ Release notes
 
 Current release
 ---------------
-Psycopg 3.0.3
-^^^^^^^^^^^^^
-
-- Fix disable cursors methods after close() (:ticket:`#125`).
-
 
 Psycopg 3.0.2
 ^^^^^^^^^^^^^
@@ -22,7 +17,7 @@ Psycopg 3.0.2
 - Fix type hint for `Connection.notifies()` (:ticket:`#128`).
 - Fix call to `MultiRange.__setitem__()` with a non-iterable value and a
   slice, now raising a `TypeError` (:ticket:`#129`).
-
+- Fix disable cursors methods after close() (:ticket:`#125`).
 
 Psycopg 3.0.1
 ^^^^^^^^^^^^^
index d050a7186f5449f4278d1516ac4df77d732adc38..43ed3c6bf815f95775767a7f5a84859e698124dc 100644 (file)
@@ -126,6 +126,8 @@ class ServerCursorHelper(Generic[ConnectionType, Row]):
     def _fetch_gen(
         self, cur: BaseCursor[ConnectionType, Row], num: Optional[int]
     ) -> PQGen[List[Row]]:
+        if cur.closed:
+            raise e.InterfaceError("the cursor is closed")
         # If we are stealing the cursor, make sure we know its shape
         if not self.described:
             yield from cur._start_query()
index 6686621d66f61d49c515c29cfd31929ed18d474f..a35aad107fc4257dc08d899fe858b6635bd66a93 100644 (file)
@@ -120,6 +120,52 @@ def test_close_idempotent(conn):
     cur.close()
 
 
+def test_cursor_close_fetchone(conn):
+    cur = conn.cursor("foo")
+    assert not cur.closed
+
+    query = "select * from generate_series(1, 10)"
+    cur.execute(query)
+    for _ in range(5):
+        cur.fetchone()
+
+    cur.close()
+    assert cur.closed
+
+    with pytest.raises(e.InterfaceError):
+        cur.fetchone()
+
+
+def test_cursor_close_fetchmany(conn):
+    cur = conn.cursor("foo")
+    assert not cur.closed
+
+    query = "select * from generate_series(1, 10)"
+    cur.execute(query)
+    assert len(cur.fetchmany(2)) == 2
+
+    cur.close()
+    assert cur.closed
+
+    with pytest.raises(e.InterfaceError):
+        cur.fetchmany(2)
+
+
+def test_cursor_close_fetchall(conn):
+    cur = conn.cursor("foo")
+    assert not cur.closed
+
+    query = "select * from generate_series(1, 10)"
+    cur.execute(query)
+    assert len(cur.fetchall()) == 10
+
+    cur.close()
+    assert cur.closed
+
+    with pytest.raises(e.InterfaceError):
+        cur.fetchall()
+
+
 def test_close_noop(conn, recwarn, retries):
     for retry in retries:
         with retry: