[Django] #33820: Querying null in JSONField is different between 3.2 and 4.0

5 views
Skip to first unread message

Django

unread,
Jul 1, 2022, 11:30:30 PM7/1/22
to django-...@googlegroups.com
#33820: Querying null in JSONField is different between 3.2 and 4.0
-------------------------------------+-------------------------------------
Reporter: Johnny | Owner: nobody
Metz |
Type: Bug | Status: new
Component: Database | Version: 4.0
layer (models, ORM) |
Severity: Normal | Keywords: JSONField
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Let's say I have a Django model with a `JSONField`:

{{{
class Event(models.Model):
data = models.JSONField()
}}}


And I create the following objects:

{{{
event1 = Event.objects.create(data={"key": None})
event2 = Event.objects.create(data={"key": "null"})
}}}

In Django 3.2.13, the following queries return some results:

{{{
Event.objects.filter(data__key=Value("null"))
# [event1]

Event.objects.filter(data__key="null")
# [event2]
}}}

In Django 4.0.5, the same queries return different results:

{{{
Event.objects.filter(data__key=Value("null"))
# [event1, event2]

Event.objects.filter(data__key="null")
# [event1, event2]
}}}

The [https://docs.djangoproject.com/en/4.0/topics/db/queries/#querying-
jsonfield Django docs] aren't clear which results are correct. I would
lean towards the v3 results.

I'm happy to work on a patch if people think this is a bug in v4.

--
Ticket URL: <https://code.djangoproject.com/ticket/33820>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages