diff options
author | Simon Charette <charette.s@gmail.com> | 2023-04-20 00:25:57 -0400 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-24 08:32:44 +0200 |
commit | d660cee5bc68b597503c2a16f3d9928d52f93fb4 (patch) | |
tree | 7d809a0fa4e5d49d45f5c09252fb971a7463701f /tests/filtered_relation | |
parent | 3fe0c609cf6d50e45e1246492ebac02660561177 (diff) | |
download | django-d660cee5bc68b597503c2a16f3d9928d52f93fb4.tar.gz |
Fixed #33766 -- Resolved FilteredRelation.condition at referencing time.
The previous implementation resolved condition at Join compilation time
which required introducing a specialized expression resolving mode to
alter the join reuse logic solely during that phase.
FilteredRelation.condition is now resolved when the relation is first
referenced which maintains the existing behavior while allowing the
removal of the specialized resolving mode and address an issue where
conditions couldn't spawn new joins.
Diffstat (limited to 'tests/filtered_relation')
-rw-r--r-- | tests/filtered_relation/tests.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/filtered_relation/tests.py b/tests/filtered_relation/tests.py index 0fce8b092a..2cceeb82e7 100644 --- a/tests/filtered_relation/tests.py +++ b/tests/filtered_relation/tests.py @@ -793,6 +793,47 @@ class FilteredRelationAggregationTests(TestCase): qs.annotate(total=Count("pk")).values("total"), [{"total": 1}] ) + def test_condition_spans_join(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_editor_author=FilteredRelation( + "author", condition=Q(author__name__icontains=F("editor__name")) + ) + ).filter( + contains_editor_author__isnull=False, + ), + [self.book1], + ) + + def test_condition_spans_join_chained(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_editor_author=FilteredRelation( + "author", condition=Q(author__name__icontains=F("editor__name")) + ), + contains_editor_author_ref=FilteredRelation( + "author", + condition=Q(author__name=F("contains_editor_author__name")), + ), + ).filter( + contains_editor_author_ref__isnull=False, + ), + [self.book1], + ) + + def test_condition_self_ref(self): + self.assertSequenceEqual( + Book.objects.annotate( + contains_author=FilteredRelation( + "author", + condition=Q(title__icontains=F("author__name")), + ) + ).filter( + contains_author__isnull=False, + ), + [self.book1], + ) + class FilteredRelationAnalyticalAggregationTests(TestCase): @classmethod |