summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsobolevn <mail@sobolevn.me>2024-05-03 11:40:50 +0300
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-05-04 11:34:12 +0200
commit9b5029f04851878923e04085591b29ee291718b6 (patch)
tree9a66f5b3507d7d6061e4f685eee5685d43947e68
parentac9e18f1c4f17d956d203779df1b22faeffa670f (diff)
[5.0.x] Fixed #35426 -- Updated querysets to be a required argument of GenericPrefetch.
Backport of 9a27c76021f934201cccf12215514a3091325ec8 from main.
-rw-r--r--django/contrib/contenttypes/prefetch.py2
-rw-r--r--docs/ref/contrib/contenttypes.txt2
-rw-r--r--docs/releases/5.0.5.txt3
-rw-r--r--tests/contenttypes_tests/test_models.py8
4 files changed, 13 insertions, 2 deletions
diff --git a/django/contrib/contenttypes/prefetch.py b/django/contrib/contenttypes/prefetch.py
index b02ed3bae5..97ac60295b 100644
--- a/django/contrib/contenttypes/prefetch.py
+++ b/django/contrib/contenttypes/prefetch.py
@@ -3,7 +3,7 @@ from django.db.models.query import ModelIterable, RawQuerySet
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 71feee63e0..cec6b488e9 100644
--- a/docs/ref/contrib/contenttypes.txt
+++ b/docs/ref/contrib/contenttypes.txt
@@ -598,7 +598,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 bb1d732167..7e7963e707 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 1999364dd5..17cdc95677 100644
--- a/tests/contenttypes_tests/test_models.py
+++ b/tests/contenttypes_tests/test_models.py
@@ -333,6 +333,14 @@ class ContentTypesMultidbTests(TestCase):
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):