1
0
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:
Clément Escolano
2023-08-01 23:31:40 +02:00
committed by Mariusz Felisiak
parent 190874eadd
commit cac94dd8aa
15 changed files with 473 additions and 42 deletions

View File

@@ -2,6 +2,7 @@ from unittest import mock
from django.db import transaction
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils.deprecation import RemovedInDjango60Warning
from .models import Article, InheritedArticleA, InheritedArticleB, Publication, User
@@ -561,3 +562,23 @@ class ManyToManyTests(TestCase):
self.assertEqual(
self.p3.article_set.exists(), self.p3.article_set.all().exists()
)
def test_get_prefetch_queryset_warning(self):
articles = Article.objects.all()
msg = (
"get_prefetch_queryset() is deprecated. Use get_prefetch_querysets() "
"instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
self.a1.publications.get_prefetch_queryset(articles)
def test_get_prefetch_querysets_invalid_querysets_length(self):
articles = Article.objects.all()
msg = (
"querysets argument of get_prefetch_querysets() should have a length of 1."
)
with self.assertRaisesMessage(ValueError, msg):
self.a1.publications.get_prefetch_querysets(
instances=articles,
querysets=[Publication.objects.all(), Publication.objects.all()],
)