diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-06-14 11:04:17 -0400 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-06-30 20:15:25 -0300 |
| commit | 192bc7a7be92e20cc250907fb4083df689715679 (patch) | |
| tree | fce1eb3bd023873a28abde83b557dd83e65fe46a /tests/composite_pk | |
| parent | ff0ff98d427982b7225df59f454a86bdf66251d6 (diff) | |
Fixed #36464 -- Fixed "__in" tuple lookup on backends lacking native support.
When native support for tuple lookups is missing in a DB backend, it can
be emulated with an EXISTS clause. This is controlled by the backend
feature flag "supports_tuple_lookups".
The mishandling of subquery right-hand side in `TupleIn` (added to
support `CompositePrimaryKey` in Refs #373) was likely missed because
the only core backend we test with the feature flag disabled
(Oracle < 23.4) supports it natively.
Thanks to Nandana Raol for the report, and to Sarah Boyce, Jacob Walls,
and Natalia Bidart for reviews.
Diffstat (limited to 'tests/composite_pk')
| -rw-r--r-- | tests/composite_pk/test_filter.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py index c00b6660d8..03037d4d82 100644 --- a/tests/composite_pk/test_filter.py +++ b/tests/composite_pk/test_filter.py @@ -1,3 +1,6 @@ +from unittest.mock import patch + +from django.db import connection from django.db.models import ( Case, F, @@ -246,6 +249,10 @@ class CompositePKFilterTests(TestCase): Comment.objects.filter(user=self.user_1).contains(self.comment_1), True ) + def test_filter_query_does_not_mutate(self): + queryset = User.objects.filter(comments__in=Comment.objects.all()) + self.assertEqual(str(queryset.query), str(queryset.query)) + def test_filter_users_by_comments_in(self): c1, c2, c3, c4, c5 = ( self.comment_1, @@ -541,3 +548,12 @@ class CompositePKFilterTests(TestCase): ).filter(filtered_tokens=(1, 1)), [self.tenant_1], ) + + +@skipUnlessDBFeature("supports_tuple_lookups") +class CompositePKFilterTupleLookupFallbackTests(CompositePKFilterTests): + def setUp(self): + feature_patch = patch.object( + connection.features, "supports_tuple_lookups", False + ) + self.enterContext(feature_patch) |
