Skip to content

Commit

Permalink
Fix several bugs reated to MilvusClient (#1948)
Browse files Browse the repository at this point in the history
Signed-off-by: zhenshan.cao <[email protected]>
  • Loading branch information
czs007 authored Mar 5, 2024
1 parent 6f4046c commit b594692
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
20 changes: 12 additions & 8 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_collection(
primary_field_name: str = "id", # default is "id"
id_type: str = "int", # or "string",
vector_field_name: str = "vector", # default is "vector"
metric_type: str = "IP",
metric_type: str = "COSINE",
auto_id: bool = False,
timeout: Optional[float] = None,
schema: Optional[CollectionSchema] = None,
Expand Down Expand Up @@ -91,9 +91,9 @@ def _fast_create_collection(
collection_name: str,
dimension: int,
primary_field_name: str = "id", # default is "id"
id_type: str = "int", # or "string",
id_type: Union[DataType, str] = DataType.INT64, # or "string",
vector_field_name: str = "vector", # default is "vector"
metric_type: str = "IP",
metric_type: str = "COSINE",
auto_id: bool = False,
timeout: Optional[float] = None,
**kwargs,
Expand All @@ -106,9 +106,9 @@ def _fast_create_collection(

schema = self.create_schema(auto_id=auto_id, **kwargs)

if id_type == "int":
if id_type in ("int", DataType.INT64):
pk_data_type = DataType.INT64
elif id_type in ("string", "str"):
elif id_type in ("string", "str", DataType.VARCHAR):
pk_data_type = DataType.VARCHAR
else:
raise PrimaryKeyException(message=ExceptionsMessage.PrimaryFieldType)
Expand Down Expand Up @@ -607,10 +607,11 @@ def _create_collection_with_schema(
schema.verify()
if kwargs.get("auto_id", False):
schema.auto_id = True
if kwargs.get("enable_dynamic_field", False):
schema.enable_dynamic_field = True
schema.verify()

if schema.enable_dynamic_field is None:
schema.enable_dynamic_field = kwargs.get("enable_dynamic_field", False)

conn = self._get_connection()
if "consistency_level" not in kwargs:
kwargs["consistency_level"] = DEFAULT_CONSISTENCY_LEVEL
Expand Down Expand Up @@ -895,7 +896,10 @@ def describe_role(
res = conn.select_grant_for_one_role(role_name, db_name, timeout=timeout, **kwargs)
except Exception as ex:
raise ex from ex
return [dict(i) for i in res.groups]
ret = {}
ret["role"] = role_name
ret["privileges"] = [dict(i) for i in res.groups]
return ret

def list_roles(self, timeout: Optional[float] = None, **kwargs):
conn = self._get_connection()
Expand Down
7 changes: 6 additions & 1 deletion pymilvus/orm/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(self, fields: List, description: str = "", **kwargs):
self._kwargs = copy.deepcopy(kwargs)
self._fields = []
self._description = description
self._enable_dynamic_field = self._kwargs.get("enable_dynamic_field", False)
# if "enable_dynamic_field" is not in kwargs, we keep None here
self._enable_dynamic_field = self._kwargs.get("enable_dynamic_field", None)
self._primary_field = None
self._partition_key_field = None

Expand Down Expand Up @@ -225,6 +226,10 @@ def enable_dynamic_field(self):

@enable_dynamic_field.setter
def enable_dynamic_field(self, value: bool):
if value is None:
# we keep None here
self._enable_dynamic_field = value
return
self._enable_dynamic_field = bool(value)

def to_dict(self):
Expand Down

0 comments on commit b594692

Please sign in to comment.