summaryrefslogtreecommitdiff
path: root/tests/filtered_relation
diff options
context:
space:
mode:
authorRob <tienrobertnguyenn@gmail.com>2019-05-07 00:42:56 +1000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-07 14:47:50 +0200
commit6b736dd0747dc77473f1f7b691c196ef5912d7dd (patch)
treec4b9e8256905ddf6cd5a08c1ab4ad8b338e662ab /tests/filtered_relation
parent21aa2a5e785eef1f47beb1c3760fdd7d8915ae09 (diff)
downloaddjango-6b736dd0747dc77473f1f7b691c196ef5912d7dd.tar.gz
Fixed #30349 -- Fixed QuerySet.exclude() on FilteredRelation.
Using annotated FilteredRelations raised a FieldError when coupled with exclude(). This is due to not passing filtered relation fields to the subquery created in split_exclude(). We fixed this issue by passing the filtered relation data to the newly created subquery. Secondly, in the case where an INNER JOIN is used in the excluded subquery, the ORM would trim the filtered relation INNER JOIN in attempt to simplify the query. This will also remove the ON clause filters generated by the FilteredRelation. We added logic to not trim the INNER JOIN if it is from FilteredRelation.
Diffstat (limited to 'tests/filtered_relation')
-rw-r--r--tests/filtered_relation/tests.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/filtered_relation/tests.py b/tests/filtered_relation/tests.py
index 5e85dff16c..52fe64dfa5 100644
--- a/tests/filtered_relation/tests.py
+++ b/tests/filtered_relation/tests.py
@@ -98,6 +98,14 @@ class FilteredRelationTests(TestCase):
[self.author1]
)
+ def test_with_exclude(self):
+ self.assertSequenceEqual(
+ Author.objects.annotate(
+ book_alice=FilteredRelation('book', condition=Q(book__title__iexact='poem by alice')),
+ ).exclude(book_alice__isnull=False),
+ [self.author2],
+ )
+
def test_with_join_and_complex_condition(self):
self.assertSequenceEqual(
Author.objects.annotate(