Opened 39 minutes ago

Last modified 28 minutes ago

#37403 assigned Bug

JSONIn crashes at database level when preparing a models.Value(None, models.CharField()) on SQLite

Reported by: Jacob Walls Owned by: Clifford Gama
Component: Database layer (models, ORM) Version: 6.1
Severity: Release blocker Keywords: json, output_field, null
Cc: Clifford Gama Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Value(None, output_field=CharField()) represents SQL NULL and compiles without bound parameters. This query worked on 6.0 on SQLite:

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)
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:

  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:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 4 supplied.

Change History (1)

comment:1 by Clifford Gama, 28 minutes ago

Owner: set to Clifford Gama
Status: new → assigned
Note: See TracTickets for help on using tickets.
Back to Top