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

Extend return type of django.views.generic.list.ListView.get_queryset to allow any iterable #897

Closed

Conversation

codeinthehole
Copy link

@codeinthehole codeinthehole commented Mar 29, 2022

Which can return either a QuerySet or an iterable. See, e.g.
https://github.com/django/django/blob/83c803f161044fbfbfcd9a0c94ca93dc131be662/django/views/generic/list.py#L26-L27

This has been true for the generic ListView class since at least Django 1.7:
https://github.com/django/django/blob/1.6/django/views/generic/list.py#L24-L27

Happy to write some tests if you can point my in the right direction for how to do that.

@@ -18,7 +18,7 @@ class MultipleObjectMixin(Generic[T], ContextMixin):
paginator_class: Type[Paginator] = ...
page_kwarg: str = ...
ordering: Sequence[str] = ...
def get_queryset(self) -> QuerySet[T]: ...
def get_queryset(self) -> Union[QuerySet[T], Iterable[Any]]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterable[Any] or Iterable[T]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing, we try to use less Union return types, where possible.
This will force our users to always check what exactly was returned. Which is not very nice.

Which can return either a `QuerySet` or an iterable. See, e.g.
https://github.com/django/django/blob/83c803f161044fbfbfcd9a0c94ca93dc131be662/django/views/generic/list.py#L26-L27

This has always been true for the generic `ListView` class.
@flaeppe
Copy link
Member

flaeppe commented Jul 30, 2024

I will close this with the argument found in #2174, that the method named get_queryset returns a QuerySet

@flaeppe flaeppe closed this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants