From f7e9db14bbd39a393260d0a8b44aae80cbb65c81 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 11 Aug 2019 19:42:27 -0400 Subject: [PATCH] Refs #25367 -- Added test for Exists() lookup rhs. --- tests/lookup/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 5629515a59..7bf436ad7a 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -5,6 +5,7 @@ from operator import attrgetter from django.core.exceptions import FieldError from django.db import connection +from django.db.models.expressions import Exists, OuterRef from django.db.models.functions import Substr from django.test import TestCase, skipUnlessDBFeature @@ -932,3 +933,12 @@ class LookupTests(TestCase): field = query.model._meta.get_field('nulled_text_field') self.assertIsInstance(query.build_lookup(['isnull_none_rhs'], field, None), IsNullWithNoneAsRHS) self.assertTrue(Season.objects.filter(pk=season.pk, nulled_text_field__isnull_none_rhs=True)) + + def test_exact_exists(self): + qs = Article.objects.filter(pk=OuterRef('pk')) + seasons = Season.objects.annotate( + pk_exists=Exists(qs), + ).filter( + pk_exists=Exists(qs), + ) + self.assertCountEqual(seasons, Season.objects.all())