--- /dev/null
+.. change::
+ :tags: bug, postgresql, regression
+ :tickets: 11005
+
+ Fixed regression caused by just-released fix for :ticket:`10863` where an
+ invalid exception class were added to the "except" block, which does not
+ get exercised unless such a catch actually happens. A mock-style test has
+ been added to ensure this catch is exercised in unit tests.
+
# try to gracefully close; see #10717
# timeout added in asyncpg 0.14.0 December 2017
await_(self._connection.close(timeout=2))
- except (asyncio.TimeoutError, OSError, self.dbapi.PostgresError):
+ except (
+ asyncio.TimeoutError,
+ OSError,
+ self.dbapi.asyncpg.PostgresError,
+ ):
# in the case where we are recycling an old connection
# that may have already been disconnected, close() will
# fail with the above timeout. in this case, terminate
with expect_raises(dataclasses.FrozenInstanceError):
r1.lower = 8 # type: ignore
+ @testing.only_on("postgresql+asyncpg")
+ def test_asyncpg_terminate_catch(self):
+ """test for #11005"""
+
+ with testing.db.connect() as connection:
+ emulated_dbapi_connection = connection.connection.dbapi_connection
+
+ async def boom():
+ raise OSError("boom")
+
+ with mock.patch.object(
+ emulated_dbapi_connection,
+ "_connection",
+ mock.Mock(close=mock.Mock(return_value=boom())),
+ ) as mock_asyncpg_connection:
+ emulated_dbapi_connection.terminate()
+
+ eq_(
+ mock_asyncpg_connection.mock_calls,
+ [mock.call.close(timeout=2), mock.call.terminate()],
+ )
+
def test_version_parsing(self):
def mock_conn(res):
return mock.Mock(