diff --git a/django/contrib/contenttypes/prefetch.py b/django/contrib/contenttypes/prefetch.py index b02ed3bae573..97ac60295bb4 100644 --- a/django/contrib/contenttypes/prefetch.py +++ b/django/contrib/contenttypes/prefetch.py @@ -3,7 +3,7 @@ class GenericPrefetch(Prefetch): - def __init__(self, lookup, querysets=None, to_attr=None): + def __init__(self, lookup, querysets, to_attr=None): for queryset in querysets: if queryset is not None and ( isinstance(queryset, RawQuerySet) diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt index fa446796594e..5aad2a4ec726 100644 --- a/docs/ref/contrib/contenttypes.txt +++ b/docs/ref/contrib/contenttypes.txt @@ -603,7 +603,7 @@ information. .. versionadded:: 5.0 -.. class:: GenericPrefetch(lookup, querysets=None, to_attr=None) +.. class:: GenericPrefetch(lookup, querysets, to_attr=None) This lookup is similar to ``Prefetch()`` and it should only be used on ``GenericForeignKey``. The ``querysets`` argument accepts a list of querysets, diff --git a/docs/releases/5.0.5.txt b/docs/releases/5.0.5.txt index bb1d732167ba..7e7963e707da 100644 --- a/docs/releases/5.0.5.txt +++ b/docs/releases/5.0.5.txt @@ -30,3 +30,6 @@ Bugfixes * Fixed a bug in Django 5.0 that caused a migration crash when altering a ``GeneratedField`` referencing a renamed field (:ticket:`35422`). + +* Fixed a bug in Django 5.0 where the ``querysets`` argument of + ``GenericPrefetch`` was not required (:ticket:`35426`). diff --git a/tests/contenttypes_tests/test_models.py b/tests/contenttypes_tests/test_models.py index 88f715ceffcf..799f1cc58c74 100644 --- a/tests/contenttypes_tests/test_models.py +++ b/tests/contenttypes_tests/test_models.py @@ -331,6 +331,14 @@ def test_multidb(self): class GenericPrefetchTests(TestCase): + def test_querysets_required(self): + msg = ( + "GenericPrefetch.__init__() missing 1 required " + "positional argument: 'querysets'" + ) + with self.assertRaisesMessage(TypeError, msg): + GenericPrefetch("question") + def test_values_queryset(self): msg = "Prefetch querysets cannot use raw(), values(), and values_list()." with self.assertRaisesMessage(ValueError, msg):