mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
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.
This commit is contained in:
parent
d3e746ace5
commit
0ff46591ac
11 changed files with 230 additions and 30 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue