#32252: Using __isnull=True on a KeyTransform should not match JSON null on
SQLite
and Oracle
-------------------------------------+-------------------------------------
Reporter: sage | Owner: sage
Type: Bug | Status: assigned
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `KeyTransformIsNull` lookup borrows the logic from `HasKey` for
`isnull=False`, which is correct. If `isnull=True`, the query should only
match objects that do not have the key. The query is correct for MariaDB,
MySQL, and PostgreSQL. However, on SQLite and Oracle, the query also
matches objects that have the key with the value `null`, which is
incorrect.
To confirm, edit
`tests.model_fields.test_jsonfield.TestQuerying.test_isnull_key`. For the
first assertion, change
{{{
self.assertSequenceEqual(
NullableJSONModel.objects.filter(value__a__isnull=True),
self.objs[:3] + self.objs[5:],
)
}}}
to
{{{
self.assertSequenceEqual(
NullableJSONModel.objects.filter(value__j__isnull=True),
self.objs[:4] + self.objs[5:],
)
}}}
The test previously only checks with `value__a` which could not catch this
behavior because the value is not JSON `null`.
--
Ticket URL: <https://code.djangoproject.com/ticket/32252>
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/052.50b66a81b50eea20422b19d69d639c42%40djangoproject.com.