#34254: Exists annotations can return non-boolean results (i.e. None) if used
with
an empty QuerySet.
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Exists | Triage Stage: Accepted
EmptyQuerySet sqlite postgres |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* stage: Unreviewed => Accepted
Comment:
Thanks for the detailed report Keryn.
I suspect the solution is as simple as setting
`Exists.empty_result_set_value = False` which was missed in
dd1fa3a31b4680c0d3712e6ae122b878138580c7 and since `Exists` sublasses
`Subquery` it inherited its `.empty_result_set_value = None`.
{{{#!python
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
index c270ef16c7..fc1d94fefb 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -1548,6 +1548,7 @@ def get_group_by_cols(self):
class Exists(Subquery):
template = "EXISTS(%(subquery)s)"
output_field = fields.BooleanField()
+ empty_result_set_value = False
def __init__(self, queryset, **kwargs):
super().__init__(queryset, **kwargs)
}}}
If you can confirm this addresses the problem you reported could you
submit a PR with a regression test?
--
Ticket URL: <https://code.djangoproject.com/ticket/34254#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185a8fd7efa-2a64159f-89ef-43b9-9506-08cf2f893fed-000000%40eu-central-1.amazonses.com.