-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlalchemy.dialects.postgresql.asyncpg.InterfaceError - cannot perform operation: another operation is in progress #863
Comments
this usually is someone using the same AsyncSession object in more than one async task at a time, not any different from if they did this with the asyncpg connection directly. |
Actually, I solved this already. I was making parallel requests and using the same This issue is solved. |
I am facing same error |
The pool class should not influence this issue, so it's rather strange that changing it fixes the issue |
the person who had parallel requests on a single session likely had a different issue than the person switching to NullPool, who has a different problem. nobody ever wants to share reproducing examples so the best we can do is watch as everyone mis-configures their applications to work around issues that are likely still manifest in their code. |
We were hit by this issue as well and the reason was due to pytest creating a different event loop for each test. By forcing the same event loop for all tests (see pytest-dev/pytest-asyncio#38 (comment)) we were able to fix the problem. Note though, that the problem does not happen when one uses a @zzzeek do you have any ideas how could we solve this without forcing a unique event loop? Below is the code that can replicate the issue from sqlalchemy.sql import text
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.pool import NullPool
engine = create_async_engine(
"postgresql+asyncpg://user:password@localhost:5432/db_name", future=True#, poolclass=NullPool
)
async def test_echo():
async with engine.begin() as conn:
r = await conn.execute(text("SELECT 'hello' as echo"))
assert r.scalar() == "hello"
async def test_echo2():
async with engine.begin() as conn:
r = await conn.execute(text("SELECT 'hello' as echo"))
assert r.scalar() == "hello"
async def test_echo3():
async with engine.begin() as conn:
r = await conn.execute(text("SELECT 'hello' as echo"))
assert r.scalar() == "hello" |
dunno, we use pytest and we dont have that problem. but we rolled the async test thing ourselves, maybe report this as a bug to whatever pytest extension this is? |
@harshitsinghai77 It would be awesome, if you could provide your solution. 🙂 |
Isso ainda é um problema. E usar a classe |
I switched 2 companies since I wrote my last comment. I don't remember anything now. Lol. |
Update: async engine creation as below makes the test work half of the time, and not just the first one.
|
I still hit the same issue. We're looking for a solution. |
if someone help my solution:
|
the issue with a local PostgreSQL install?: I'm using local PostgreSQL
uvloop?:
I'm using async sqlalchemy with
postgresql+asyncpg
.I've created a FastAPI.
Here's my code snippet.
This works fine when only one request is called. But simultaneously calling the API results in this error
I'm using different session for each request with
But it still doesn't work.
The text was updated successfully, but these errors were encountered: