Closed
Description
- asyncpg version: 0.25.0
- PostgreSQL version: 13
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: I'm using local PostgreSQL - Python version: 3.8.0
- Platform: Linux
- Do you use pgbouncer?: no
- Did you install asyncpg with pip?: No, poetry
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and
uvloop?:
I'm using async sqlalchemy with postgresql+asyncpg
.
I've created a FastAPI.
Here's my code snippet.
DATABASE_URL = (
f"postgresql+asyncpg://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)
metadata = MetaData()
Base = declarative_base()
async_engine = create_async_engine(DATABASE_URL, pool_size=20)
async_session = AsyncSession(async_engine)
async with async_session as session:
query = (
nemo_user_analytics.select()
.with_only_columns(
[
func.to_char(nemo_user_analytics.c.full_date, "Mon DD").label(
"weekday"
),
func.sum(nemo_user_analytics.c.duration).label("total_count"),
]
)
.where(
and_(
nemo_user_analytics.c.full_date > seven_day_interval_before,
nemo_user_analytics.c.google_id == google_id,
)
)
.group_by("weekday")
.order_by("weekday")
)
result = await session.execute(query)
result = result.fetchall()
return result
This works fine when only one request is called. But simultaneously calling the API results in this error
sqlalchemy.exc.InterfaceError: (sqlalchemy.dialects.postgresql.asyncpg.InterfaceError) <class 'asyncpg.exceptions._base.InterfaceError'>: cannot perform operation: another operation is in progress
I'm using different session for each request with
async with async_session as session:
But it still doesn't work.
Metadata
Metadata
Assignees
Labels
No labels