'async_generator is not a callable object' dependency issue

See original GitHub issue

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 https://github.com/tiangolo/fastapi/pull/2331#issuecomment-821941735_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jcf-devcommented, Apr 18, 2021

you shouldn’t call get_db. Try just Depends(get_db)

it worked! wow. thanks a lot 💯 I’m such a dumbass

1reaction
lesnik512commented, Apr 18, 2021

you shouldn’t call get_db. Try just Depends(get_db)

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - 'async_generator is not a callable object' FastAPI ...
I am trying to create a FastAPI and async sqlalchemy. The get_db dependency causes a weird TypeError: < ...
Read more >
Strange behavior with await in a generator expression
Perhaps we can make the "TypeError: 'async_generator' object is not iterable" error message a bit clearer. Any ideas to improve it are welcome....
Read more >
TypeError: 'generator' object is not callable in Python
The Python TypeError: 'generator' object is not callable occurs when we try to call a generator object as if it were a function....
Read more >
python/typing - Gitter
With async def agen(): yield , the type of agen() is AsyncGenerator. A Coroutine is the object returned by calling an async function...
Read more >
TypeError on Rasa 3.0 'NoneType' object is not callable
Please update these packages and dependencies issues and even pip version also give issue. python-engineio==4.3.0 python-socketio==5.5.0 rasa== ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found