diff options
| author | Vignesh Anand <vigneshanandmay13@gmail.com> | 2026-03-25 03:24:02 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-24 17:54:02 -0400 |
| commit | 386257b33eb2a925cecc1a12ba5e7dd694617186 (patch) | |
| tree | 009adead91837190914e87a76bd9dd909963eaad /tests/model_fields | |
| parent | 10ea59be19e5c88631511b9c11e74852e7b8d530 (diff) | |
Refs #36494 -- Prevented crash in JSONField numeric lookups with expressions.
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/test_jsonfield.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py index 7b07a48a1e..6171fa7c6d 100644 --- a/tests/model_fields/test_jsonfield.py +++ b/tests/model_fields/test_jsonfield.py @@ -1304,6 +1304,35 @@ class TestQuerying(TestCase): ).first() self.assertEqual(result.coalesced_value, "This is valid JSON primitive.") + def test_numeric_lookups_with_expression(self): + obj_greater = NullableJSONModel.objects.create( + value={"target": 5, "comparison": 2} + ) + obj_lesser = NullableJSONModel.objects.create( + value={"target": 2, "comparison": 5} + ) + obj_equal = NullableJSONModel.objects.create( + value={"target": 2, "comparison": 2} + ) + objs = [obj_greater.pk, obj_lesser.pk, obj_equal.pk] + + tests = [ + ("gt", [obj_greater]), + ("lt", [obj_lesser]), + ("gte", [obj_greater, obj_equal]), + ("lte", [obj_lesser, obj_equal]), + ] + + for lookup, expected in tests: + with self.subTest(lookup=lookup): + self.assertCountEqual( + NullableJSONModel.objects.filter( + id__in=objs, + **{f"value__target__{lookup}": F("value__comparison")}, + ), + expected, + ) + @skipUnlessDBFeature("supports_primitives_in_json_field") class JSONNullTests(TestCase): |
