Skip to content

'async_generator is not a callable object' dependency issue #3096

@jcf-dev

Description

@jcf-dev

The get_db dependency causes a weird
TypeError: <async_generator object get_db at 0x7ff6d9d9aa60> is not a callable object
issue on my project.

Here's my code:

db.py

from typing import Generator
from .db.session import SessionLocal

async def get_db() -> Generator:
    try:
        db = SessionLocal()
        yield db
    finally:
        await db.close()

session.py

from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from .core.config import settings

engine = create_async_engine(
    settings.SQLALCHEMY_DATABASE_URI,
    pool_pre_ping=True
)
SessionLocal = AsyncSession(
    autocommit=False,
    autoflush=False,
    bind=engine
)

Originally posted by @joweenflores in #2331 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions