#36085: SQLite backend raises exception on negative array indices in JSONField
-------------------------------------+-------------------------------------
               Reporter:  savanto    |          Owner:  savanto
                   Type:  Bug        |         Status:  assigned
              Component:  Database   |        Version:  5.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  sqlite, jsonfield
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Positive jsonfield array index queries can be constructed the usual way
 with kwargs (ie. `Model.objects.filter(jsonfield__2=1)`), while negative
 jsonfield array index query must be constructed using the splat operator
 on a dict: `Model.objects.filter(**{"jsonfield__-2": 1})`). When querying
 jsonfields in this way **on the SQLite backend**, the following error
 arises:

 {{{django.db.utils.OperationalError: bad JSON path: '$[-2]'}}}

 When constructing the query, the JSON path constructor simply appends any
 numerical value to the path
 
(https://github.com/django/django/blob/5.1.4/django/db/models/fields/json.py#L155).
 But the SQLite backend uses a special syntax for performing negative-
 indexing in jsonfields (https://sqlite.org/json1.html#path_arguments) that
 is different from other backends: negative indices must be prepended by a
 literal `#` character.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36085>
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/0107019456bf8d34-42b32e5f-9ddf-41b5-9744-194a0ee1fc8d-000000%40eu-central-1.amazonses.com.

Reply via email to