Skip to content

error: "HttpRequest" has no attribute "query_params" #74

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

Closed
sobolevn opened this issue Jul 3, 2020 · 1 comment
Closed

error: "HttpRequest" has no attribute "query_params" #74

sobolevn opened this issue Jul 3, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@sobolevn
Copy link
Member

sobolevn commented Jul 3, 2020

This code produces a false-positive mypy error:

class MyViewset(
    mixins.ListModelMixin,
    GenericViewSet,
):
    def get_queryset(self):
        office_id = int(self.request.query_params['office_id'])  # here
        ...

Output:

» mypy server
server/rest_app/views.py:144: error: "HttpRequest" has no attribute "query_params"
Found 1 errors in 1 files (checked 199 source files)

Versions:

My wild guest is that self.request is considered to be server/rest_app/views.py:144: note: Revealed type is 'django.http.request.HttpRequest' there, not the Request provided by the drf.

This fixes the issue:

class MyViewset(
    mixins.ListModelMixin,
    GenericViewSet,
):
    request: Request
@sobolevn sobolevn added the bug Something isn't working label Jul 3, 2020
@sobolevn
Copy link
Member Author

sobolevn commented Jul 3, 2020

In runtime it is the same type: <rest_framework.request.Request object at 0x10ea93f90> <class 'rest_framework.request.Request'>

sobolevn added a commit that referenced this issue Jul 3, 2020
sobolevn added a commit that referenced this issue Jul 3, 2020
sobolevn added a commit that referenced this issue Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant