#37403: JSONIn crashes at database level when preparing a models.Value(None,
models.CharField()) on SQLite
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 6.1 | Severity: Release
| blocker
Keywords: json, output_field, | Triage Stage:
null | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
`Value(None, output_field=CharField())` represents SQL `NULL` and compiles
without bound parameters. This query worked on 6.0 on SQLite:
{{{#!py
from django.db import models
class Person(models.Model):
metadata = models.JSONField()
def run():
qs = Person.objects.filter(metadata__in=[models.Value(None,
models.CharField())])
print(qs)
}}}
{{{#!sql
SELECT "app_person"."id",
"app_person"."metadata"
FROM "app_person"
WHERE "app_person"."metadata" IN (NULL)
LIMIT 21
}}}
But after 9b8e4c6d7d47f7b2e96817ba334e9fd53c10a0df (6.1), it crashes on
SQLite with:
{{{#!py
File "/Users/jwalls/django/django/db/models/lookups.py", line 349, in
<genexpr>
self.resolve_expression_parameter(compiler, connection, sql, param)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jwalls/django/django/db/models/fields/json.py", line 444,
in resolve_expression_parameter
and params[0] not in connection.ops.jsonfield_datatype_values
~~~~~~^^^
IndexError: list index out of range
}}}
And differently on 6.1.2 after #37377, at the database level:
{{{#!py
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
current statement uses 3, and there are 4 supplied.
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/37403>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.