SynchronousOnlyOperation: async usage in sync context
SynchronousOnlyOperation: async in sync
$ python - <<'PY'
import asyncio
async def a(): return 1
try:
a()
except Exception as e:
print(type(e).__name__, e)
PY
RuntimeWarning coroutine 'a' was never awaited
Why this happens
You invoked async ORM or async functions directly in a sync view.
Fix
Use async def views with ASGI or wrap with async_to_sync where appropriate.
Wrong code
result = async_func()
Fixed code
from asgiref.sync import async_to_sync
result = async_to_sync(async_func)()