mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #33651 -- Added support for prefetching GenericForeignKey.
Co-authored-by: revanthgss <revanthgss@almabase.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
committed by
Mariusz Felisiak
parent
190874eadd
commit
cac94dd8aa
@@ -4,6 +4,7 @@ from copy import deepcopy
|
||||
from django.core.exceptions import FieldError, MultipleObjectsReturned
|
||||
from django.db import IntegrityError, models, transaction
|
||||
from django.test import TestCase
|
||||
from django.utils.deprecation import RemovedInDjango60Warning
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
from .models import (
|
||||
@@ -877,3 +878,49 @@ class ManyToOneTests(TestCase):
|
||||
usa.cities.remove(chicago.pk)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
usa.cities.set([chicago.pk])
|
||||
|
||||
def test_get_prefetch_queryset_warning(self):
|
||||
City.objects.create(name="Chicago")
|
||||
cities = City.objects.all()
|
||||
msg = (
|
||||
"get_prefetch_queryset() is deprecated. Use get_prefetch_querysets() "
|
||||
"instead."
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
City.country.get_prefetch_queryset(cities)
|
||||
|
||||
def test_get_prefetch_queryset_reverse_warning(self):
|
||||
usa = Country.objects.create(name="United States")
|
||||
City.objects.create(name="Chicago")
|
||||
countries = Country.objects.all()
|
||||
msg = (
|
||||
"get_prefetch_queryset() is deprecated. Use get_prefetch_querysets() "
|
||||
"instead."
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
usa.cities.get_prefetch_queryset(countries)
|
||||
|
||||
def test_get_prefetch_querysets_invalid_querysets_length(self):
|
||||
City.objects.create(name="Chicago")
|
||||
cities = City.objects.all()
|
||||
msg = (
|
||||
"querysets argument of get_prefetch_querysets() should have a length of 1."
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
City.country.get_prefetch_querysets(
|
||||
instances=cities,
|
||||
querysets=[Country.objects.all(), Country.objects.all()],
|
||||
)
|
||||
|
||||
def test_get_prefetch_querysets_reverse_invalid_querysets_length(self):
|
||||
usa = Country.objects.create(name="United States")
|
||||
City.objects.create(name="Chicago")
|
||||
countries = Country.objects.all()
|
||||
msg = (
|
||||
"querysets argument of get_prefetch_querysets() should have a length of 1."
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
usa.cities.get_prefetch_querysets(
|
||||
instances=countries,
|
||||
querysets=[City.objects.all(), City.objects.all()],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user