@@ -119,9 +119,44 @@ def delete_keys(payload, keys):
119119 # element by index is not idempotent), so both sides leave it untouched
120120 delete_keys ({"loc" : [{"x" : 1 }, {"x" : 2 }]}, ["loc[0]" ])
121121
122+ # a terminal wildcard clears the array instead
123+ delete_keys ({"loc" : [1 , 2 , 3 ], "top" : 9 }, ["loc[]" ])
124+
125+ # arrays are not implicitly flattened: "loc.x" does not reach into elements,
126+ # unlike in filters, where "loc.x" and "loc[].x" are equivalent
127+ delete_keys ({"loc" : [{"x" : 1 , "y" : 2 }]}, ["loc.x" ])
128+
129+ # a dotted path never matches a literal key containing a dot
130+ delete_keys ({"a.b" : 1 , "a" : {"b" : 2 }}, ["a.b" ])
131+
132+ # nested wildcards clear each inner array
133+ delete_keys ({"loc" : [[1 , 2 ], [3 , 4 ]]}, ["loc[][]" ])
134+
122135 # top-level and nested keys together
123136 delete_keys ({"a" : {"b" : 1 }, "top" : 9 }, ["a.b" , "top" ])
124137
138+ # an invalid json path rejects the whole request on both sides: nothing is
139+ # deleted, not even for the keys preceding the invalid one. "loc[-1]" is
140+ # invalid too: the server addresses array elements with an unsigned index.
141+ for invalid_key in ("not a valid path" , "loc[-1]" , "loc[-1].x" ):
142+ for client in (local_client , remote_client ):
143+ client .upsert (
144+ collection_name = COLLECTION_NAME ,
145+ points = [
146+ PointStruct (id = 9999 , payload = {"a" : {"b" : 1 }, "loc" : [1 , 2 ]}, vector = vector ),
147+ PointStruct (id = 10000 , payload = {"a" : {"b" : 1 }, "loc" : [1 , 2 ]}, vector = vector ),
148+ ],
149+ wait = True ,
150+ )
151+ with pytest .raises ((ValueError , UnexpectedResponse , grpc .RpcError )):
152+ client .delete_payload (
153+ collection_name = COLLECTION_NAME ,
154+ keys = ["a.b" , invalid_key ],
155+ points = [9999 , 10000 ],
156+ wait = True ,
157+ )
158+ compare_collections (local_client , remote_client , 2 )
159+
125160
126161@pytest .mark .parametrize ("prefer_grpc" , [True , False ])
127162def test_clear_payload (prefer_grpc ):
0 commit comments