#35381: Provide `JSONNull` expression to represent JSON `null` value
-------------------------------------+-------------------------------------
Reporter: Olivier Tabone | Owner: Clifford
| Gama
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Another edge case of the dual interpretation of `None`
[https://docs.djangoproject.com/en/5.2/topics/db/queries/#storing-and-
querying-for-none when storing and querying JSONField] (SQL `NULL` on
persisting and `filter(json_field=None)` on filtering) that came up at
work today is how it breaks `get_or_create` expectations that the filter
and creation value will match.
It means that doing
{{{#!python
Foo.objects.get_or_create(bar=123, json_field=None)
}}}
will perform
{{{#!python
SELECT * FROM foo WHERE bar = 123 AND json_field = 'null'::jsonb
INSERT INTO foo (bar, json_field) VALUES (123, NULL)
}}}
using `JSONNull()` allows for JSON `null` to be used in both cases
(querying and storing) but there are no ways to specify that SQL `NULL`
must be used in both cases.
--
Ticket URL: <https://code.djangoproject.com/ticket/35381#comment:17>
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 visit
https://groups.google.com/d/msgid/django-updates/010701981de54a83-8a9719e5-2d09-4095-bf0e-ad635afe9cbc-000000%40eu-central-1.amazonses.com.