jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception "got Future <Future pending> attached to a different loop"

jcam5826 opened this issue · comments

In the celery_task.py file you have this ...

@celery.task(name="tasks.print_hero")
def print_hero(hero_id: UUID) -> None:
    hero = runnify(get_hero)(hero_id=hero_id)
    return hero.id

I found an issue in implementing a version of the above code in my project. After a task is run once, I was getting a cryptic exception "got Future attached to a different loop". After a lot of head scratching, the following resolved the problem.

    asyncio.get_event_loop().run_until_complete(get_hero(hero_id=hero_id))

Sorry, I have not taken the time to confirm that your project has the same problem. I'm posting just in case someone else runs into the problem.

Thank you for your excellent project. It has helped a lot.

Hello @jcam5826 I am sorry for the late reply and thanks for your positive feedback. Sure I am going to check this bug you had in your custom project and replicate it.

Hello, @jcam5826 I was able to replicate the bug and I have updated the code as you suggest here using asyncio.get_event_loop().run_until_complete()
0378bdb