From: Daniele Varrazzo Date: Wed, 28 Oct 2020 16:45:03 +0000 (+0100) Subject: Raise InterfaceError on operation on closed objects X-Git-Tag: 3.0.dev0~422 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e035be545eec7b1a12184d58e6d88607bcb57ba;p=thirdparty%2Fpsycopg.git Raise InterfaceError on operation on closed objects --- diff --git a/psycopg3/psycopg3/cursor.py b/psycopg3/psycopg3/cursor.py index 236165621..31ccc3fa3 100644 --- a/psycopg3/psycopg3/cursor.py +++ b/psycopg3/psycopg3/cursor.py @@ -142,10 +142,10 @@ class BaseCursor: from .adapt import Transformer if self.closed: - raise e.OperationalError("the cursor is closed") + raise e.InterfaceError("the cursor is closed") if self.connection.closed: - raise e.OperationalError("the connection is closed") + raise e.InterfaceError("the connection is closed") if self.connection.status != self.connection.ConnStatus.OK: raise e.InterfaceError( diff --git a/tests/test_cursor.py b/tests/test_cursor.py index a50b9bbec..b874af294 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -11,7 +11,7 @@ def test_close(conn): cur.close() assert cur.closed - with pytest.raises(psycopg3.OperationalError): + with pytest.raises(psycopg3.InterfaceError): cur.execute("select 'foo'") cur.close() diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 37598b950..53c3cf2a3 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -13,7 +13,7 @@ async def test_close(aconn): await cur.close() assert cur.closed - with pytest.raises(psycopg3.OperationalError): + with pytest.raises(psycopg3.InterfaceError): await cur.execute("select 'foo'") await cur.close()