@@ -785,6 +785,21 @@ def test_shallow_list_lookup(self):
785785 [self .objs [5 ]],
786786 )
787787
788+ @skipIfDBFeature ("supports_json_negative_indexing" )
789+ def test_unsupported_negative_lookup (self ):
790+ msg = (
791+ "Using negative JSON array indices is not supported on this database "
792+ "backend."
793+ )
794+ with self .assertRaisesMessage (NotSupportedError , msg ):
795+ NullableJSONModel .objects .filter (** {"value__-2" : 1 }).get ()
796+
797+ @skipUnlessDBFeature ("supports_json_negative_indexing" )
798+ def test_shallow_list_negative_lookup (self ):
799+ self .assertSequenceEqual (
800+ NullableJSONModel .objects .filter (** {"value__-2" : 1 }), [self .objs [5 ]]
801+ )
802+
788803 def test_shallow_obj_lookup (self ):
789804 self .assertCountEqual (
790805 NullableJSONModel .objects .filter (value__a = "b" ),
@@ -817,12 +832,26 @@ def test_deep_lookup_array(self):
817832 [self .objs [5 ]],
818833 )
819834
835+ @skipUnlessDBFeature ("supports_json_negative_indexing" )
836+ def test_deep_negative_lookup_array (self ):
837+ self .assertSequenceEqual (
838+ NullableJSONModel .objects .filter (** {"value__-1__0" : 2 }),
839+ [self .objs [5 ]],
840+ )
841+
820842 def test_deep_lookup_mixed (self ):
821843 self .assertSequenceEqual (
822844 NullableJSONModel .objects .filter (value__d__1__f = "g" ),
823845 [self .objs [4 ]],
824846 )
825847
848+ @skipUnlessDBFeature ("supports_json_negative_indexing" )
849+ def test_deep_negative_lookup_mixed (self ):
850+ self .assertSequenceEqual (
851+ NullableJSONModel .objects .filter (** {"value__d__-1__f" : "g" }),
852+ [self .objs [4 ]],
853+ )
854+
826855 def test_deep_lookup_transform (self ):
827856 self .assertCountEqual (
828857 NullableJSONModel .objects .filter (value__c__gt = 2 ),
0 commit comments