mirror of
https://github.com/django/django.git
synced 2024-11-21 10:59:04 +01:00
Fixed #35426 -- Updated querysets to be a required argument of GenericPrefetch.
This commit is contained in:
parent
32d163e680
commit
9a27c76021
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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`).
|
||||
|
@ -331,6 +331,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):
|
||||
|
Loading…
Reference in New Issue
Block a user