Skip to content

Instantly share code, notes, and snippets.

@mohitt
Created January 23, 2022 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohitt/d56a3e3d0569ccf01f26038b0b810462 to your computer and use it in GitHub Desktop.
Save mohitt/d56a3e3d0569ccf01f26038b0b810462 to your computer and use it in GitHub Desktop.
# Following throws exception with sessionmaker and asyncpg connection string
inspector = inspect(engine)
return inspector.has_table(table_name, schema_name)
../../../.virtualenvs/vocore-IesooB9o/lib/python3.9/site-packages/sqlalchemy/engine/create.py:576: in connect
return dialect.connect(*cargs, **cparams)
../../../.virtualenvs/vocore-IesooB9o/lib/python3.9/site-packages/sqlalchemy/engine/default.py:548: in connect
return self.dbapi.connect(*cargs, **cparams)
../../../.virtualenvs/vocore-IesooB9o/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:744: in connect
await_only(self.asyncpg.connect(*arg, **kw)),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
awaitable = <coroutine object connect at 0x7ff752c61b40>
def await_only(awaitable: Coroutine) -> Any:
"""Awaits an async function in a sync method.
The sync method must be inside a :func:`greenlet_spawn` context.
:func:`await_` calls cannot be nested.
:param awaitable: The coroutine to call.
"""
# this is called in the context greenlet while running fn
current = greenlet.getcurrent()
if not isinstance(current, _AsyncIoGreenlet):
> raise exc.MissingGreenlet(
"greenlet_spawn has not been called; can't call await_() here. "
"Was IO attempted in an unexpected place?"
)
E sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_() here. Was IO attempted in an unexpected place? (Background on this error at: http://sqlalche.me/e/14/xd2s)
../../../.virtualenvs/vocore-IesooB9o/lib/python3.9/site-packages/sqlalchemy/util/_concurrency_py3k.py:47: MissingGreenlet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment