#35426: `GenericPrefetch` should have `queryset` parameter as required
-------------------------------------+-------------------------------------
Reporter: Sobolev | Owner: Sobolev Nikita
Nikita |
Type: | Status: assigned
Uncategorized |
Component: | Version: 5.0
contrib.contenttypes |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Original issue:
https://code.djangoproject.com/ticket/33651
Source:
https://github.com/django/django/blob/91a4b9a8ec2237434f06866f39c7977e889aeae6/django/contrib/contenttypes/prefetch.py#L6-L7
Right now this code is really strange. It produces this result:
```
>>> import django
>>> from django.contrib.contenttypes.prefetch import GenericPrefetch
>>> GenericPrefetch('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Documents/github/wemake-django-
template/.venv/lib/python3.11/site-
packages/django/contrib/contenttypes/prefetch.py", line 7, in __init__
for queryset in querysets:
TypeError: 'NoneType' object is not iterable
```
I guess that there are two ways:
- Using `if querysets is None: querysets = []`
- Requiring this argument, which I guess is the correct thing to do. Why
would we ever want this field to be empty?
I will send a PR with the fix.
I found this while working on
https://github.com/typeddjango/django-
stubs/pull/2115
--
Ticket URL: <
https://code.djangoproject.com/ticket/35426>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.