#32398: Excluding on annotations doesn't apply null handling.
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Roman Odaisky):
Or sometimes the null handling is applied in places where it should not be
applied:
{{{
def isblank(value, true_or_false):
"""Basically the equivalent of `(not value) == true_or_false`"""
return Exact(Exact(value, 0) | IsNull(value, True), true_or_false)
def lookupify(function):
class LookupifyLookup(Lookup):
prepare_rhs = False
def as_sql(self, compiler, connection):
return compiler.compile(
function(self.lhs, self.rhs)
.resolve_expression(compiler.query)
)
return LookupifyLookup
Field.register_lookup(lookupify(isblank), "isblank")
SomeModel.objects.exclude(isblank(F("field"), True))
# correctly excludes zeroes and nulls
SomeModel.objects.exclude(field__isblank=True)
# only excludes zeroes but not nulls!
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32398#comment:20>
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/0107018bb9c8dba1-a1b0b353-e395-437e-a424-cc44288345dd-000000%40eu-central-1.amazonses.com.