diff --git a/pymilvus/client/prepare.py b/pymilvus/client/prepare.py index 840cc0bab..d72bf7e29 100644 --- a/pymilvus/client/prepare.py +++ b/pymilvus/client/prepare.py @@ -393,6 +393,10 @@ def _is_input_field(field: Dict, is_upsert: bool): "is_function_output", False ) + @staticmethod + def _function_output_field_names(fields_info: List[Dict]): + return [field["name"] for field in fields_info if field.get("is_function_output", False)] + @staticmethod def _num_input_fields(fields_info: List[Dict], is_upsert: bool): return len([field for field in fields_info if Prepare._is_input_field(field, is_upsert)]) @@ -407,6 +411,7 @@ def _parse_row_request( input_fields_info = [ field for field in fields_info if Prepare._is_input_field(field, is_upsert=False) ] + function_output_field_names = Prepare._function_output_field_names(fields_info) fields_data = { field["name"]: schema_types.FieldData(field_name=field["name"], type=field["type"]) for field in input_fields_info @@ -426,10 +431,16 @@ def _parse_row_request( msg = f"expected Dict, got '{type(entity).__name__}'" raise TypeError(msg) for k, v in entity.items(): - if k not in fields_data and not enable_dynamic: - raise DataNotMatchException( - message=ExceptionsMessage.InsertUnexpectedField % k - ) + if k not in fields_data: + if k in function_output_field_names: + raise DataNotMatchException( + message=ExceptionsMessage.InsertUnexpectedFunctionOutputField % k + ) + + if not enable_dynamic: + raise DataNotMatchException( + message=ExceptionsMessage.InsertUnexpectedField % k + ) if k in fields_data: field_info, field_data = field_info_map[k], fields_data[k] @@ -482,6 +493,7 @@ def _parse_upsert_row_request( input_fields_info = [ field for field in fields_info if Prepare._is_input_field(field, is_upsert=True) ] + function_output_field_names = Prepare._function_output_field_names(fields_info) fields_data = { field["name"]: schema_types.FieldData(field_name=field["name"], type=field["type"]) for field in input_fields_info @@ -501,10 +513,16 @@ def _parse_upsert_row_request( msg = f"expected Dict, got '{type(entity).__name__}'" raise TypeError(msg) for k, v in entity.items(): - if k not in fields_data and not enable_dynamic: - raise DataNotMatchException( - message=ExceptionsMessage.InsertUnexpectedField % k - ) + if k not in fields_data: + if k in function_output_field_names: + raise DataNotMatchException( + message=ExceptionsMessage.InsertUnexpectedFunctionOutputField % k + ) + + if not enable_dynamic: + raise DataNotMatchException( + message=ExceptionsMessage.InsertUnexpectedField % k + ) if k in fields_data: field_info, field_data = field_info_map[k], fields_data[k] diff --git a/pymilvus/exceptions.py b/pymilvus/exceptions.py index 5505f5b7a..4ffe503b6 100644 --- a/pymilvus/exceptions.py +++ b/pymilvus/exceptions.py @@ -242,6 +242,9 @@ class ExceptionsMessage: InsertUnexpectedField = ( "Attempt to insert an unexpected field `%s` to collection without enabling dynamic field" ) + InsertUnexpectedFunctionOutputField = ( + "Attempt to insert an unexpected function output field `%s` to collection" + ) InsertMissedField = ( "Insert missed an field `%s` to collection without set nullable==true or set default_value" )