Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] no Response object generated for ASGI api route #1168

Open
brendenwest opened this issue May 16, 2024 · 1 comment
Open

[BUG] no Response object generated for ASGI api route #1168

brendenwest opened this issue May 16, 2024 · 1 comment

Comments

@brendenwest
Copy link

brendenwest commented May 16, 2024

Describe the bug
I'm running Django under ASGI and basic api routes are working fine. But when I follow the django-ninja documentation for an api route using a Schema response, I get this error:

'QuerySet' object has no attribute 'status_code'

requirements.txt

gunicorn==21.2.0
uvicorn[standard]==0.29.0
httptools==0.6.1
uvloop==0.19.0
asgiref==3.8.1

django==5.0.4
django-ninja==1.1.0

Route definition

class PersonSchema(ModelSchema):
    class Config:
        model = User
        model_fields = ["id", "username"]


@api.get("/people/", response=List[PersonSchema])
def people(request):
    return User.objects.all()

Versions (please complete the following information):

  • Python version: [3.10, 3.11, 3.12]
  • Django version: [4.x, 5.x]
  • Django-Ninja version: [1.1.0, 1.0, 0.22.0]
  • Pydantic version: [-na-]

Traceback

024-05-16 10:36:25 Traceback (most recent call last):
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 518, in thread_handler
2024-05-16 10:36:25     raise exc_info[1]
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 42, in inner
2024-05-16 10:36:25     response = await get_response(request)
2024-05-16 10:36:25                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/django/utils/deprecation.py", line 152, in __acall__
2024-05-16 10:36:25     response = await sync_to_async(
2024-05-16 10:36:25                ^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 468, in __call__
2024-05-16 10:36:25     ret = await asyncio.shield(exec_coro)
2024-05-16 10:36:25           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
2024-05-16 10:36:25     result = self.fn(*self.args, **self.kwargs)
2024-05-16 10:36:25              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 522, in thread_handler
2024-05-16 10:36:25     return func(*args, **kwargs)
2024-05-16 10:36:25            ^^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25   File "/usr/local/lib/python3.12/site-packages/django/middleware/common.py", line 107, in process_response
2024-05-16 10:36:25     if response.status_code == 404 and self.should_redirect_with_slash(request):
2024-05-16 10:36:25        ^^^^^^^^^^^^^^^^^^^^
2024-05-16 10:36:25 AttributeError: 'QuerySet' object has no attribute 'status_code'

Other traceback
image

@brendenwest
Copy link
Author

Same behavior under Hypercorn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant