.. seealso::
- :ref:`asyncio extension <asyncio_toplevel>`
+ :ref:`asyncio_toplevel`
+
+.. _error_xd2s:
+
+MissingGreenlet
+---------------
+
+A call to the async :term:`DBAPI` was initiated outside the greenlet spawn context
+usually setup by the SQLAlchemy AsyncIO proxy classes.
+Usually this error happens when an IO was attempted in an unexpected
+place, without using the provided async api.
+When using the ORM this may be due to a lazy loading attempt, which
+is unsupported when using SQLAlchemy with AsyncIO dialects.
+
+.. seealso::
+
+ :ref:`_session_run_sync`
Core Exception Classes
code = "xd1r"
+class MissingGreenlet(InvalidRequestError):
+ r"""Error raised by the async greenlet await\_ if called while not inside
+ the greenlet spawn context.
+
+ """
+
+ code = "xd2s"
+
+
class NoReferencedTableError(NoReferenceError):
"""Raised by ``ForeignKey`` when the referred ``Table`` cannot be
located.
# this is called in the context greenlet while running fn
current = greenlet.getcurrent()
if not isinstance(current, _AsyncIoGreenlet):
- raise exc.InvalidRequestError(
- "greenlet_spawn has not been called; can't call await_() here."
+ raise exc.MissingGreenlet(
+ "greenlet_spawn has not been called; can't call await_() here. "
+ "Was IO attempted in an unexpected place?"
)
# returns the control to the driver greenlet passing it
if not isinstance(current, _AsyncIoGreenlet):
loop = asyncio.get_event_loop()
if loop.is_running():
- raise exc.InvalidRequestError(
+ raise exc.MissingGreenlet(
"greenlet_spawn has not been called and asyncio event "
- "loop is already running; can't call await_() here."
+ "loop is already running; can't call await_() here. "
+ "Was IO attempted in an unexpected place?"
)
return loop.run_until_complete(awaitable)
async def test_await_only_no_greenlet(self):
to_await = run1()
with expect_raises_message(
- exc.InvalidRequestError,
+ exc.MissingGreenlet,
r"greenlet_spawn has not been called; can't call await_\(\) here.",
):
await_only(to_await)
await_fallback(inner_await())
with expect_raises_message(
- exc.InvalidRequestError,
+ exc.MissingGreenlet,
"greenlet_spawn has not been called and asyncio event loop",
):
await greenlet_spawn(go)