I’m looking to access my Django ORM in the temporal async context in Python. However, when I run a function that calls asgiref.sync.sync_to_async
, it breaks because there is a function called run_in_executor
which is implemented in the base Asyncio event loop but not in the _WorkflowInstanceImpl
event loop implemented by temporalio.
Is there a solution or workaround to be able to access the Django ORM?
{
"message": "'_WorkflowInstanceImpl' object has no attribute '_check_closed'",
"stackTrace": " File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/temporalio/worker/_workflow_instance.py\", line 377, in activate\n self._run_once(check_conditions=index == 1 or index == 2)\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/temporalio/worker/_workflow_instance.py\", line 1790, in _run_once\n raise self._current_activation_error\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/temporalio/worker/_workflow_instance.py\", line 1808, in _run_top_level_workflow_function\n await coro\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/temporalio/worker/_workflow_instance.py\", line 857, in run_workflow\n result = await self._inbound.execute_workflow(input)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/temporalio/worker/_workflow_instance.py\", line 2140, in execute_workflow\n return await input.run_fn(*args)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n\n File \"/Users/yuming/work/didero/didero-api/didero/workflows/core/workflow_definitions.py\", line 176, in run\n workflow_run_model_instance = await WorkflowRun.objects.aget(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/django/db/models/query.py\", line 649, in aget\n return await sync_to_async(self.get)(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n File \"/Users/yuming/work/didero/didero-api/.venv/lib/python3.11/site-packages/asgiref/sync.py\", line 455, in __call__\n exec_coro = loop.run_in_executor(\n ^^^^^^^^^^^^^^^^^^^^^\n\n File \"/Users/yuming/.pyenv/versions/3.11.1/lib/python3.11/asyncio/base_events.py\", line 816, in run_in_executor\n self._check_closed()\n ^^^^^^^^^^^^^^^^^^\n",
"applicationFailureInfo": {
"type": "AttributeError"
}
}