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

ListView.get_queryset() cannot be treated as a queryset #1928

Closed
michjnich opened this issue Feb 5, 2024 · 0 comments · Fixed by #2191
Closed

ListView.get_queryset() cannot be treated as a queryset #1928

michjnich opened this issue Feb 5, 2024 · 0 comments · Fixed by #2191
Labels
bug Something isn't working

Comments

@michjnich
Copy link

Bug report

What's wrong

The return type of get_queryset on a ListView seems to be _SupportsPagination[Any], which is throwing an error when I try and add a select_related to the queryset.

Apologies if I'm missing something here (entirely possible!), but I've been going back and forth. I can see it's coming from the MultipleObjectMixin.

def get_queryset(self) -> _SupportsPagination[_M]: ...

class MyModelList(ListView): 
    ...
    
    def get_queryset(self): -> QuerySet[Any]:
        qs = super().get_queryset().select_related("city")

There's nothing overly complicated about the model setup here, I just want to add the select related to the base queryset.

How is that should be

super().get_queryset() should (probably?) not throw a type error when I treat it as a queryset in a ListView

System information

  • OS: Ubuntu 20.04.6 LTS (5.15.133.1-microsoft-standard-WSL2 under Windows 11)
  • python version: 3.11.5
  • django version: 5.0.1
  • mypy version: 1.8.0
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7
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

Successfully merging a pull request may close this issue.

1 participant