diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-06 05:54:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 05:54:35 +0200 |
commit | 69fa2e8eb25d9bdd395fa8857177d4637aaf4c55 (patch) | |
tree | 53f9207a991b8865d8d03c3b7587f2cfbcd89d91 /tests/prefetch_related | |
parent | 19e0587ee596debf77540d6a08ccb6507e60b6a7 (diff) | |
download | django-69fa2e8eb25d9bdd395fa8857177d4637aaf4c55.tar.gz |
Refs #26780 -- Made prefetch_related() don't use window expressions fo sliced queries if not supported.
Diffstat (limited to 'tests/prefetch_related')
-rw-r--r-- | tests/prefetch_related/tests.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 0ac0586476..4c92ccc9ca 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -2,11 +2,16 @@ from unittest import mock from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist -from django.db import connection +from django.db import NotSupportedError, connection from django.db.models import Prefetch, QuerySet, prefetch_related_objects from django.db.models.query import get_prefetcher from django.db.models.sql import Query -from django.test import TestCase, override_settings +from django.test import ( + TestCase, + override_settings, + skipIfDBFeature, + skipUnlessDBFeature, +) from django.test.utils import CaptureQueriesContext, ignore_warnings from django.utils.deprecation import RemovedInDjango50Warning @@ -1911,6 +1916,7 @@ class NestedPrefetchTests(TestCase): class PrefetchLimitTests(TestDataMixin, TestCase): + @skipUnlessDBFeature("supports_over_clause") def test_m2m_forward(self): authors = Author.objects.all() # Meta.ordering with self.assertNumQueries(3): @@ -1924,6 +1930,7 @@ class PrefetchLimitTests(TestDataMixin, TestCase): with self.subTest(book=book): self.assertEqual(book.authors_sliced, list(book.authors.all())[1:]) + @skipUnlessDBFeature("supports_over_clause") def test_m2m_reverse(self): books = Book.objects.order_by("title") with self.assertNumQueries(3): @@ -1937,6 +1944,7 @@ class PrefetchLimitTests(TestDataMixin, TestCase): with self.subTest(author=author): self.assertEqual(author.books_sliced, list(author.books.all())[1:2]) + @skipUnlessDBFeature("supports_over_clause") def test_foreignkey_reverse(self): authors = Author.objects.order_by("-name") with self.assertNumQueries(3): @@ -1960,6 +1968,7 @@ class PrefetchLimitTests(TestDataMixin, TestCase): list(book.first_time_authors.all())[1:], ) + @skipUnlessDBFeature("supports_over_clause") def test_reverse_ordering(self): authors = Author.objects.reverse() # Reverse Meta.ordering with self.assertNumQueries(3): @@ -1972,3 +1981,13 @@ class PrefetchLimitTests(TestDataMixin, TestCase): for book in books: with self.subTest(book=book): self.assertEqual(book.authors_sliced, list(book.authors.all())[1:]) + + @skipIfDBFeature("supports_over_clause") + def test_window_not_supported(self): + authors = Author.objects.all() + msg = ( + "Prefetching from a limited queryset is only supported on backends that " + "support window functions." + ) + with self.assertRaisesMessage(NotSupportedError, msg): + list(Book.objects.prefetch_related(Prefetch("authors", authors[1:]))) |