# Python SDK Event Loop Missing sync\_to\_async?

**URL:** <https://community.temporal.io/t/python-sdk-event-loop-missing-sync-to-async/15016>\
**Category:** Community Support\
**Created:** [November 7, 2024, 4:54pm UTC](https://community.temporal.io/t/python-sdk-event-loop-missing-sync-to-async/15016 "2024-11-07T16:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuming](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yuming/32/6278_2.png) [@yuming](https://community.temporal.io/u/yuming)\
**Post date:** [November 7, 2024, 4:54pm UTC](https://community.temporal.io/t/python-sdk-event-loop-missing-sync-to-async/15016/1 "2024-11-07T16:54:51Z")

</div>

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?

```auto
{
  "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"
  }
}

```

---

<div class="post-metadata">

**Author:** ![yuming](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yuming/32/6278_2.png) [@yuming](https://community.temporal.io/u/yuming)\
**Post date:** [December 17, 2024, 11:50pm UTC](https://community.temporal.io/t/python-sdk-event-loop-missing-sync-to-async/15016/2 "2024-12-17T23:50:55Z")

</div>

Anyone have an answer to this? It seems like the Temporal event loop in python is missing some features from the asyncio event loop?

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [December 18, 2024, 1:21pm UTC](https://community.temporal.io/t/python-sdk-event-loop-missing-sync-to-async/15016/3 "2024-12-18T13:21:30Z")

</div>

Workflows must be deterministic. You cannot make ORM/DB calls from inside a workflow. This is intentionally not implemented and you must use an activity to do side-effecting things in a workflow.
