﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26908	jsonfield__key__isnull lookup crashes on PostgreSQL 9.4	Luca Simone Sigfrido Percich	PREMANAND	"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
}}}
"	Bug	closed	contrib.postgres	1.9	Normal	fixed	jsonb,postgresql	Marc Tamlyn	Accepted	1	0	0	0	0	0
