#32483: QuerySet.values()/values_list() with JSONField returns integers instead 
of
booleans on SQLite.
-------------------------------------+-------------------------------------
     Reporter:  Matthew Cornell      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Documentation        |                  Version:  3.1
     Severity:  Normal               |               Resolution:
     Keywords:  jsonfield querying   |             Triage Stage:  Accepted
  sqlite                             |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * component:  Database layer (models, ORM) => Documentation
 * severity:  Release blocker => Normal


Comment:

 It seems there is not much we can do, the SQL query is correct.
 Unfortunately `JSON_EXTRACT()` returns integers for boolean values and
 it's a [https://www.sqlite.org/json1.html#jex documented] behavior:

 > ''The json_extract(X,P1,P2,...) extracts and returns one or more values
 from the well-formed JSON at X. If only a single path P1 is provided, then
 the SQL datatype of the result is NULL for a JSON null, INTEGER or REAL
 for a JSON numeric value, **an INTEGER zero for a JSON false value, an
 INTEGER one for a JSON true value**, ...''

 There is no way to recognize that we should automatically cast a value to
 boolean, you can use `Cast('json_field__is_true', models.BooleanField())`.

 Changing to a documentation issue.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32483#comment:4>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/072.fcf314d44622ffe95781db2c7ed69fa6%40djangoproject.com.

Reply via email to