Refs #33482 -- Fixed QuerySet selecting and filtering againts negated Exists() with empty queryset.
Regression in b7d1da5a62
.
This commit is contained in:
parent
25514b604a
commit
6f185a53a2
|
@ -1221,7 +1221,10 @@ class Exists(Subquery):
|
|||
)
|
||||
except EmptyResultSet:
|
||||
if self.negated:
|
||||
return '', ()
|
||||
features = compiler.connection.features
|
||||
if not features.supports_boolean_expr_in_select_clause:
|
||||
return "1=1", ()
|
||||
return compiler.compile(Value(True))
|
||||
raise
|
||||
if self.negated:
|
||||
sql = 'NOT {}'.format(sql)
|
||||
|
|
|
@ -1918,6 +1918,14 @@ class ExistsTests(TestCase):
|
|||
)
|
||||
self.assertSequenceEqual(qs, [manager])
|
||||
|
||||
def test_select_negated_empty_exists(self):
|
||||
manager = Manager.objects.create()
|
||||
qs = Manager.objects.annotate(
|
||||
not_exists=~Exists(Manager.objects.none())
|
||||
).filter(pk=manager.pk)
|
||||
self.assertSequenceEqual(qs, [manager])
|
||||
self.assertIs(qs.get().not_exists, True)
|
||||
|
||||
|
||||
class FieldTransformTests(TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue