You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
... my code
await database.execute(query)
File "/usr/local/lib/python3.10/site-packages/databases/core.py", line 169, in execute
async with self.connection() as connection:
File "/usr/local/lib/python3.10/site-packages/databases/core.py", line 256, in __aenter__
raise e
File "/usr/local/lib/python3.10/site-packages/databases/core.py", line 253, in __aenter__
await self._connection.acquire()
File "/usr/local/lib/python3.10/site-packages/databases/backends/aiopg.py", line 105, in acquire
assert self._connection is None, "Connection is already acquired"
AssertionError: Connection is already acquired
In short, no, I would assume it is not. But I couldn't get consistent reproduction steps working to test it out either. Why the issue occurs is rather easily explainable however.
What is happening is that the task responsible for releasing the connection gets cancelled, which in turn raises an exception before self._connection can be set to None.
What #461 does is simply swap the two around; First it sets self._connection to None, then it releases the (old) connection, so that if the task gets canceled, it has at least reset the connection property.
I tried to reproduce this with a simple wait_for, but getting it to time out exactly during the release of the connection is quite rare.
Activity
timraay commentedon Jul 3, 2023
Still an issue as of 0.6.2. For me, the traceback that led to connections ending up in this bad state, in case it is of any help;
zanieb commentedon Jul 13, 2023
@timraay is this resolved by #546 ?
timraay commentedon Jul 16, 2023
In short, no, I would assume it is not. But I couldn't get consistent reproduction steps working to test it out either. Why the issue occurs is rather easily explainable however.
What is happening is that the task responsible for releasing the connection gets cancelled, which in turn raises an exception before
self._connectioncan be set toNone.What #461 does is simply swap the two around; First it sets
self._connectiontoNone, then it releases the (old) connection, so that if the task gets canceled, it has at least reset the connection property.I tried to reproduce this with a simple wait_for, but getting it to time out exactly during the release of the connection is quite rare.