Fixed #36612 -- Fixed a KeyTextTransform crash on MySQL against annotations.
Some checks are pending
Linters / flake8 (push) Waiting to run
Linters / isort (push) Waiting to run
Linters / black (push) Waiting to run
Tests / Windows, SQLite, Python 3.13 (push) Waiting to run
Tests / JavaScript tests (push) Waiting to run

MySQL only supports the ->> when used directly against columns, this can be
inferred by the presence of lhs.output_field.model as model bounds fields are
directly tied to columns.

Purposely don't systematically switch to using JSON_QUOTE(JSON_EXTRACT(...))
as there might be functional indices out there that rely on the SQL remaining
stable between versions.

Thanks Jacob Tavener for the report.
This commit is contained in:
Simon Charette 2025-09-17 01:56:40 -04:00 committed by Sarah Boyce
parent a36df6890d
commit af84cfba59
2 changed files with 12 additions and 2 deletions

View file

@ -1160,6 +1160,12 @@ class TestQuerying(TestCase):
True,
)
def test_cast_with_key_text_transform(self):
obj = NullableJSONModel.objects.annotate(
json_data=Cast(Value({"foo": "bar"}, JSONField()), JSONField())
).get(pk=self.objs[0].pk, json_data__foo__icontains="bar")
self.assertEqual(obj, self.objs[0])
@skipUnlessDBFeature("supports_json_field_contains")
def test_contains_contained_by_with_key_transform(self):
tests = [