Skip to content

Commit

Permalink
fix: cannot pass consistency level for delete
Browse files Browse the repository at this point in the history
See also: milvus-io#2327

Signed-off-by: yangxuan <[email protected]>
  • Loading branch information
XuanYang-cn committed Nov 15, 2024
1 parent 016ff55 commit ac302a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
12 changes: 5 additions & 7 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,15 @@ def delete(
check_pass_param(collection_name=collection_name, timeout=timeout)
try:
req = Prepare.delete_request(
collection_name,
partition_name,
expression,
consistency_level=kwargs.get("consistency_level", 0),
param_name=kwargs.pop("param_name", None),
collection_name=collection_name,
expression=expression,
partition_name=partition_name,
consistency_level=kwargs.pop("consistency_level", 0),
**kwargs,
)
future = self._stub.Delete.future(req, timeout=timeout)

if kwargs.get("_async", False):
cb = kwargs.get("_callback")
cb = kwargs.pop("_callback")
f = MutationFuture(future, cb, timeout=timeout, **kwargs)
f.add_callback(ts_utils.update_ts_on_mutation(collection_name))
return f
Expand Down
30 changes: 14 additions & 16 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,29 +734,27 @@ def batch_upsert_param(
def delete_request(
cls,
collection_name: str,
expression: str,
partition_name: str,
expr: str,
consistency_level: Optional[Union[int, str]],
consistency_level: Optional[Union[int, str]] = None,
**kwargs,
):
def check_str(instr: str, prefix: str):
if instr is None:
raise ParamError(message=f"{prefix} cannot be None")
if not isinstance(instr, str):
raise ParamError(message=f"{prefix} value {instr} is illegal")
if len(instr) == 0:
raise ParamError(message=f"{prefix} cannot be empty")

check_str(collection_name, "collection_name")
if partition_name is not None and partition_name != "":
check_str(partition_name, "partition_name")
param_name = kwargs.get("param_name", "expr")
check_str(expr, param_name)
def valid_str(var: Any) -> True:
return isinstance(var, str) and len(var) > 0

if not valid_str(collection_name):
raise ParamError(message=f"collection_name {collection_name} is illegal, expect none empty str")

if not valid_str(expression):
raise ParamError(message=f"expression {expression} is illegal, expect none empty str")

if partition_name is not None and not valid_str(partition_name):
raise ParamError(message=f"partition_name {partition_name} is illegal, expect none empty str")

return milvus_types.DeleteRequest(
collection_name=collection_name,
partition_name=partition_name,
expr=expr,
expr=expression,
consistency_level=get_consistency_level(consistency_level),
expr_template_values=cls.prepare_expression_template(kwargs.get("expr_params", {})),
)
Expand Down
17 changes: 14 additions & 3 deletions tests/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@


class TestPrepare:
@pytest.mark.parametrize("coll_name", [None, "", -1, 1.1, []])
def test_delete_request_wrong_coll_name(self, coll_name: str):
with pytest.raises(MilvusException):
Prepare.delete_request(coll_name, "id>1", None, 0)

@pytest.mark.parametrize("part_name", ["", -1, 1.1, []])
def test_delete_request_wrong_part_name(self, part_name):
with pytest.raises(MilvusException):
Prepare.delete_request("coll", "id>1", part_name, 0)


def test_search_requests_with_expr_offset(self):
fields = [
FieldSchema("pk", DataType.INT64, is_primary=True),
Expand Down Expand Up @@ -42,7 +53,7 @@ def test_search_requests_with_expr_offset(self):
params = json.loads(p.value)
if PAGE_RETAIN_ORDER_FIELD in params:
page_retain_order_exists = True
assert params[PAGE_RETAIN_ORDER_FIELD] == True
assert params[PAGE_RETAIN_ORDER_FIELD] is True

assert offset_exists is True
assert page_retain_order_exists is True
Expand Down Expand Up @@ -112,7 +123,7 @@ def test_get_schema_from_collection_schema(self):

c_schema = Prepare.get_schema_from_collection_schema("random", schema)

assert c_schema.enable_dynamic_field == False
assert c_schema.enable_dynamic_field is False
assert c_schema.name == "random"
assert len(c_schema.fields) == 2
assert c_schema.fields[0].name == "field_vector"
Expand Down Expand Up @@ -190,7 +201,7 @@ def test_row_insert_param_with_auto_id(self):
]

Prepare.row_insert_param("", rows, "", fields_info=schema.to_dict()["fields"], enable_dynamic=True)

def test_row_insert_param_with_none(self):
import numpy as np
rng = np.random.default_rng(seed=19530)
Expand Down

0 comments on commit ac302a7

Please sign in to comment.