Skip to content

Commit

Permalink
Fix has_collection result with Milvus2.2 (#1750)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
XuanYang-cn authored Oct 25, 2023
1 parent 73ab019 commit aad0f57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,19 @@ 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
and "can't find collection" in reply.status.reason
):
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()
Expand Down
2 changes: 1 addition & 1 deletion pymilvus/orm/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aad0f57

Please sign in to comment.