Coroutines inside revision #1156
-
I have similar problem with https://stackoverflow.com/questions/74727910/how-to-run-sqlalchemy-uploader-coroutines-inside-sync-alembic-migrations I need to run coroutine to fill table and I want to make this a part of migration. Is any ways to do it without threading? Because it doesn't allow to run two migrations with coroutines because of exception with "I don't close loop" (but I close). P.S. asyncio.run() inside this run infinite loop. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
if you are using the async env.py template at https://github.com/sqlalchemy/alembic/blob/main/alembic/templates/async/env.py, which will establish SQLAlchemy's async "greenlet context" around everything that's running, you can run coroutines as: from sqlalchemy.util import await_only
def upgrade():
await_only(my_coroutine()) |
Beta Was this translation helpful? Give feedback.
if you are using the async env.py template at https://github.com/sqlalchemy/alembic/blob/main/alembic/templates/async/env.py, which will establish SQLAlchemy's async "greenlet context" around everything that's running, you can run coroutines as: