diff options
| author | Simon Charette <charette.s@gmail.com> | 2022-02-01 13:27:41 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-02 07:54:19 +0100 |
| commit | b7d1da5a62fe4141beff2bfea565f7ef0038c94c (patch) | |
| tree | 5aa3e2172056bb5fa8d701f433f52a4c3018dab0 /django | |
| parent | 770d3e6a4ce8e0a91a9e27156036c1985e74d4a3 (diff) | |
Fixed #33482 -- Fixed QuerySet filtering againts negated Exists() with empty queryset.
Thanks Tobias Bengfort for the report.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/expressions.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 81f8f79c71..c71970636c 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1211,13 +1211,18 @@ class Exists(Subquery): def as_sql(self, compiler, connection, template=None, **extra_context): query = self.query.exists(using=connection.alias) - sql, params = super().as_sql( - compiler, - connection, - template=template, - query=query, - **extra_context, - ) + try: + sql, params = super().as_sql( + compiler, + connection, + template=template, + query=query, + **extra_context, + ) + except EmptyResultSet: + if self.negated: + return '', () + raise if self.negated: sql = 'NOT {}'.format(sql) return sql, params |
