You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I expect that if I write the same authenticate handlers in async and sync, they behave the same. But in reality, I get proper 401 with SyncBearerAuth and crash for AsyncBearerAuth with the same handling logic.
Traceback (mostrecentcalllast):
File"C:\Users\Marat\Desktop\csmbackend\.venv\Lib\site-packages\ninja\operation.py", line190, in_run_authenticationresult=async_to_sync(callback)(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\Marat\Desktop\csmbackend\.venv\Lib\site-packages\asgiref\sync.py", line254, in__call__returncall_result.result()
^^^^^^^^^^^^^^^^^^^^File"C:\Users\Marat\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line449, inresultreturnself.__get_result()
^^^^^^^^^^^^^^^^^^^File"C:\Users\Marat\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line401, in__get_resultraiseself._exceptionFile"C:\Users\Marat\Desktop\csmbackend\.venv\Lib\site-packages\asgiref\sync.py", line331, inmain_wrapresult=awaitself.awaitable(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: objectNoneTypecan't be used in 'await' expression
Versions (please complete the following information):
Python version: 3.12.8
Django version: 5.1.4
Django-Ninja version: 1.3.0
Pydantic version: 2.10.5
Note you can quickly get this by runninng in ./manage.py shell this line:
As you can see, the authenticate implementations are the same but no bearer header causes different behavior:
FAILED tests/test_weird_case.py::test_bearer_auth - TypeError: object NoneType can't be used in 'await' expression
The text was updated successfully, but these errors were encountered:
mmkhitaryan
changed the title
[BUG] Async authenticate() in HttpBearer causes crash
[BUG] No bearer header causes crash in async authenticate() HttpBearer
Jan 9, 2025
mmkhitaryan
added a commit
to mmkhitaryan/django-ninja
that referenced
this issue
Jan 9, 2025
Describe the bug
I expect that if I write the same
authenticate
handlers in async and sync, they behave the same. But in reality, I get proper 401 with SyncBearerAuth and crash for AsyncBearerAuth with the same handling logic.Versions (please complete the following information):
Note you can quickly get this by runninng in
./manage.py shell
this line:As you can see, the
authenticate
implementations are the same but no bearer header causes different behavior:The text was updated successfully, but these errors were encountered: