pycasbin / django-orm-adapter

Django ORM Adapter for PyCasbin
https://github.com/casbin/pycasbin
Apache License 2.0
30 stars 19 forks source link

when use "uvicorn" to start django project, will get this error "django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async." #30

Open zhangweiqaz opened 5 months ago

zhangweiqaz commented 5 months ago

File "/data/.../kubeconfig_management/venv/lib/python3.10/site-packages/casbin_adapter/apps.py", line 12, in ready initialize_enforcer(db_alias) File "/data/.../kubeconfig_management/venv/lib/python3.10/site-packages/casbin_adapter/enforcer.py", line 67, in initialize_enforcer with connect.cursor() as cursor: File "/data/.../kubeconfig_management/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 24, in inner raise SynchronousOnlyOperation(message) django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

casbin-bot commented 5 months ago

@techoner @Nekotoxin

hsluoyz commented 5 months ago

We need to add a "Async" version for this django-orm-adapter, repo here: https://github.com/pycasbin/async-django-orm-adapter

Refer to other Async version middlewares: https://github.com/pycasbin?q=async&type=all&language=&sort=