mirror of
https://github.com/django/django.git
synced 2025-10-30 17:16:10 +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
@@ -1,5 +1,6 @@
|
||||
from django.db import IntegrityError, connection, transaction
|
||||
from django.test import TestCase
|
||||
from django.utils.deprecation import RemovedInDjango60Warning
|
||||
|
||||
from .models import (
|
||||
Bar,
|
||||
@@ -606,3 +607,23 @@ class OneToOneTests(TestCase):
|
||||
self.b1.place_id = self.p2.pk
|
||||
self.b1.save()
|
||||
self.assertEqual(self.b1.place, self.p2)
|
||||
|
||||
def test_get_prefetch_queryset_warning(self):
|
||||
places = Place.objects.all()
|
||||
msg = (
|
||||
"get_prefetch_queryset() is deprecated. Use get_prefetch_querysets() "
|
||||
"instead."
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
|
||||
Place.bar.get_prefetch_queryset(places)
|
||||
|
||||
def test_get_prefetch_querysets_invalid_querysets_length(self):
|
||||
places = Place.objects.all()
|
||||
msg = (
|
||||
"querysets argument of get_prefetch_querysets() should have a length of 1."
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
Place.bar.get_prefetch_querysets(
|
||||
instances=places,
|
||||
querysets=[Bar.objects.all(), Bar.objects.all()],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user