#26908: jsonb field: error with __isnull lookup
----------------------------------+------------------------------
Reporter: sigfrido | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Keywords: jsonb,postgresql
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+------------------------------
Given this model:
{{{#!python
class MyModel(models.Model):
jsonbfield = JSONField(null=True, blank=True, default=dict)
}}}
The following filter will always result in a '''"ProgrammingError:
operator does not exist jsonb -> boolean"''':
{{{#!python
MyModel.objects.filter(jsonbfield__key__isnull=True)
}}}
That's because this is beng translated in the following SQL expression:
{{{
... where myapp_mymodel.jsonbfield -> 'key' is null
}}}
which does not yield the desired result because in postgres the ->, ->> or
#> operators have no precedence over '''is'''.
'''Fix: enclose mapping in parenthesis'''
{{{
(myapp_mymodel.jsonbfield -> 'key') is null
}}}
Relevant code:
File: django/contrib/postgres/fields/jsonb.py
row 76 and 83:
{{{#!python
return "{} #> %s".format(lhs), [key_transforms] + params
...
return "%s -> %s" % (lhs, lookup), params
}}}
Should become:
{{{#!python
return "({} #> %s)".format(lhs), [key_transforms] + params
...
return "(%s -> %s)" % (lhs, lookup), params
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26908>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.7722ccd99a44a6bd4dee97ac76627540%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.