summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorsavanto <savanto@users.noreply.github.com>2025-05-13 13:42:58 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-05-14 13:21:18 +0200
commit8620a3b0c79e4e8098b88f1176ed26fad0bf6c5c (patch)
tree4d1a2be9331f5aa702ae0b1551fe38a62786990a /tests
parenta8716f3c4c6d78d38ce86d79c816062346dcc5bf (diff)
Fixed #36085 -- Added JSONField support for negative array indexing on SQLite.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/test_jsonfield.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index 1788933774..16ab8887a9 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -785,6 +785,21 @@ class TestQuerying(TestCase):
[self.objs[5]],
)
+ @skipIfDBFeature("supports_json_negative_indexing")
+ def test_unsupported_negative_lookup(self):
+ msg = (
+ "Using negative JSON array indices is not supported on this database "
+ "backend."
+ )
+ with self.assertRaisesMessage(NotSupportedError, msg):
+ NullableJSONModel.objects.filter(**{"value__-2": 1}).get()
+
+ @skipUnlessDBFeature("supports_json_negative_indexing")
+ def test_shallow_list_negative_lookup(self):
+ self.assertSequenceEqual(
+ NullableJSONModel.objects.filter(**{"value__-2": 1}), [self.objs[5]]
+ )
+
def test_shallow_obj_lookup(self):
self.assertCountEqual(
NullableJSONModel.objects.filter(value__a="b"),
@@ -817,12 +832,26 @@ class TestQuerying(TestCase):
[self.objs[5]],
)
+ @skipUnlessDBFeature("supports_json_negative_indexing")
+ def test_deep_negative_lookup_array(self):
+ self.assertSequenceEqual(
+ NullableJSONModel.objects.filter(**{"value__-1__0": 2}),
+ [self.objs[5]],
+ )
+
def test_deep_lookup_mixed(self):
self.assertSequenceEqual(
NullableJSONModel.objects.filter(value__d__1__f="g"),
[self.objs[4]],
)
+ @skipUnlessDBFeature("supports_json_negative_indexing")
+ def test_deep_negative_lookup_mixed(self):
+ self.assertSequenceEqual(
+ NullableJSONModel.objects.filter(**{"value__d__-1__f": "g"}),
+ [self.objs[4]],
+ )
+
def test_deep_lookup_transform(self):
self.assertCountEqual(
NullableJSONModel.objects.filter(value__c__gt=2),