Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit c8171e2

Browse files
dswillraminalaee
andauthored
Fix connections counter handling BaseException (#457)
Co-authored-by: Amin Alaee <[email protected]>
1 parent 0fe0adb commit c8171e2

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ __pycache__/
88
*.egg-info/
99
htmlcov/
1010
venv/
11+
.idea/

databases/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ async def __aenter__(self) -> "Connection":
251251
try:
252252
if self._connection_counter == 1:
253253
await self._connection.acquire()
254-
except Exception as e:
254+
except BaseException as e:
255255
self._connection_counter -= 1
256256
raise e
257257
return self

tests/test_databases.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,22 @@ async def test_ddl_queries(database_url):
303303
await database.execute(query)
304304

305305

306+
@pytest.mark.parametrize("exception", [Exception, asyncio.CancelledError])
306307
@pytest.mark.parametrize("database_url", DATABASE_URLS)
307308
@mysql_versions
308309
@async_adapter
309-
async def test_queries_after_error(database_url):
310+
async def test_queries_after_error(database_url, exception):
310311
"""
311312
Test that the basic `execute()` works after a previous error.
312313
"""
313314

314-
class DBException(Exception):
315-
pass
316-
317315
async with Database(database_url) as database:
318316
with patch.object(
319317
database.connection()._connection,
320318
"acquire",
321-
new=AsyncMock(side_effect=DBException),
319+
new=AsyncMock(side_effect=exception),
322320
):
323-
with pytest.raises(DBException):
321+
with pytest.raises(exception):
324322
query = notes.select()
325323
await database.fetch_all(query)
326324

0 commit comments

Comments
 (0)