summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-09-17 01:56:40 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-09-22 09:00:24 +0200
commitaf84cfba5970fda8306860b650937701c7c03c6f (patch)
tree0678f9639fc6409874e4cc5da0dbef5ec46b8185 /tests/model_fields
parenta36df6890d8995480f2e95ba556b77cef975d4f6 (diff)
Fixed #36612 -- Fixed a KeyTextTransform crash on MySQL against annotations.
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.
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/test_jsonfield.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index 16ab8887a9..b16499d198 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -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 = [