From e556b9a0a35008ede27e7289a5703ce1cd1418cd Mon Sep 17 00:00:00 2001 From: yangxuan Date: Tue, 24 Oct 2023 17:36:41 +0800 Subject: [PATCH] Fix has_collection result with Milvus2.2 For Milvus2.2.x, PyMilvus needs to check for `error_code` before checking codes, cuz code will alwasy returns 0, which indicates rpc success Signed-off-by: yangxuan --- pymilvus/client/grpc_handler.py | 12 ++++++------ pymilvus/orm/schema.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index 714213dbc..f79881794 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -320,12 +320,6 @@ def has_collection(self, collection_name: str, timeout: Optional[float] = None, rf = self._stub.DescribeCollection.future(request, timeout=timeout) reply = rf.result() - if reply.status.code == ErrorCode.SUCCESS: - return True - - if reply.status.code == ErrorCode.COLLECTION_NOT_FOUND: - return False - # For compatibility with Milvus less than 2.3.2, which does not support status.code. if ( reply.status.error_code == common_pb2.UnexpectedError @@ -333,6 +327,12 @@ def has_collection(self, collection_name: str, timeout: Optional[float] = None, ): return False + if reply.status.code == ErrorCode.SUCCESS: + return True + + if reply.status.code == ErrorCode.COLLECTION_NOT_FOUND: + return False + raise MilvusException(reply.status.code, reply.status.reason, reply.status.error_code) @retry_on_rpc_failure() diff --git a/pymilvus/orm/schema.py b/pymilvus/orm/schema.py index 3f83a2e23..a4a295b91 100644 --- a/pymilvus/orm/schema.py +++ b/pymilvus/orm/schema.py @@ -40,7 +40,7 @@ def validate_primary_key(primary_field: Any): if primary_field is None: - raise PrimaryKeyException(message=ExceptionsMessage.PrimaryKeyNotExist) + raise PrimaryKeyException(message=ExceptionsMessage.NoPrimaryKey) if primary_field.dtype not in [DataType.INT64, DataType.VARCHAR]: raise PrimaryKeyException(message=ExceptionsMessage.PrimaryKeyType)