Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#35426 closed Bug (fixed)

`GenericPrefetch` should have `queryset` parameter as required

Reported by: Sobolev Nikita Owned by: Sobolev Nikita
Component: contrib.contenttypes Version: 5.0
Severity: Release blocker Keywords:
Cc: Sobolev Nikita Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Sobolev Nikita)

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

Change History (6)

comment:1 by Sobolev Nikita, 3 months ago

Description: modified (diff)

comment:2 by Sobolev Nikita, 3 months ago

Has patch: set

comment:3 by Sarah Boyce, 3 months ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Hi Sobelev, thank you for the report and patch!
Agreed this is a bug in cac94dd8aa2fb49cd2e06b5b37cf039257284bb0, as this is a new feature introduced in 5.0, marking as a release blocker.

comment:4 by Sarah Boyce <42296566+sarahboyce@…>, 3 months ago

Resolution: fixed
Status: assignedclosed

In 9a27c760:

Fixed #35426 -- Updated querysets to be a required argument of GenericPrefetch.

comment:5 by Sarah Boyce <42296566+sarahboyce@…>, 3 months ago

In 9b5029f0:

[5.0.x] Fixed #35426 -- Updated querysets to be a required argument of GenericPrefetch.

Backport of 9a27c76021f934201cccf12215514a3091325ec8 from main.

comment:6 by Sarah Boyce, 3 months ago

Triage Stage: AcceptedReady for checkin
Note: See TracTickets for help on using tickets.
Back to Top