diff options
| author | Simon Charette <charette.s@gmail.com> | 2022-11-02 22:03:05 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-01 19:14:00 +0100 |
| commit | 0ff46591ac3010841c73fd26e0fef93995fedd99 (patch) | |
| tree | 7373b7f028df958db09d353e603124bc52b37bed /docs/topics | |
| parent | d3e746ace5eeea07216da97d9c3801f2fdc43223 (diff) | |
Refs #33308 -- Deprecated support for passing encoded JSON string literals to JSONField & co.
JSON should be provided as literal Python objects an not in their
encoded string literal forms.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/db/queries.txt | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 5114efb57d..977e287c53 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -971,7 +971,7 @@ Storing and querying for ``None`` As with other fields, storing ``None`` as the field's value will store it as SQL ``NULL``. While not recommended, it is possible to store JSON scalar -``null`` instead of SQL ``NULL`` by using :class:`Value('null') +``null`` instead of SQL ``NULL`` by using :class:`Value(None, JSONField()) <django.db.models.Value>`. Whichever of the values is stored, when retrieved from the database, the Python @@ -987,11 +987,13 @@ query for SQL ``NULL``, use :lookup:`isnull`:: >>> Dog.objects.create(name='Max', data=None) # SQL NULL. <Dog: Max> - >>> Dog.objects.create(name='Archie', data=Value('null')) # JSON null. + >>> Dog.objects.create( + ... name='Archie', data=Value(None, JSONField()) # JSON null. + ... ) <Dog: Archie> >>> Dog.objects.filter(data=None) <QuerySet [<Dog: Archie>]> - >>> Dog.objects.filter(data=Value('null')) + >>> Dog.objects.filter(data=Value(None, JSONField()) <QuerySet [<Dog: Archie>]> >>> Dog.objects.filter(data__isnull=True) <QuerySet [<Dog: Max>]> @@ -1007,6 +1009,15 @@ Unless you are sure you wish to work with SQL ``NULL`` values, consider setting Storing JSON scalar ``null`` does not violate :attr:`null=False <django.db.models.Field.null>`. +.. versionchanged:: 4.2 + + Support for expressing JSON ``null`` using ``Value(None, JSONField())`` was + added. + +.. deprecated:: 4.2 + + Passing ``Value("null")`` to express JSON ``null`` is deprecated. + .. fieldlookup:: jsonfield.key Key, index, and path transforms |
