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

GenericAPIView is missing a typed get_queryset() method #489

Open
Kangaroux opened this issue Oct 17, 2023 · 2 comments
Open

GenericAPIView is missing a typed get_queryset() method #489

Kangaroux opened this issue Oct 17, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Kangaroux
Copy link

https://github.com/typeddjango/djangorestframework-stubs/blob/master/rest_framework-stubs/generics.pyi#L33

The missing get_queryset() causes any call to super().get_queryset() to be typed as QuerySet[Any, Any].

# Revealed type is "django.db.models.query._QuerySet[Any, Any]"
reveal_type(super().get_queryset())
  • python version: 3.9.10
  • django version: 4.2.3
  • mypy version: 1.4.1
  • django-stubs version: 4.2.3
@Kangaroux Kangaroux added the bug Something isn't working label Oct 17, 2023
@sterliakov
Copy link

It is added just a few lines above via mixin:

def get_queryset(self) -> QuerySet[_MT_co]: ...

Are you sure that you inherit e.g. GenericAPIView[MyModel] and not simply GenericAPIView? It's exactly the use of type variable here - you must pass a related model type.

@Kangaroux
Copy link
Author

@sterliakov You're right, I wasn't using that. It would be good to update the FAQ in the readme to include this example as well (there's one already for serializers).

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

2 participants