Skip to content

Commit

Permalink
Fix bug for insert ndarray in json field (#1907)
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
xiaocai2333 authored Feb 1, 2024
1 parent 4858eee commit 6e6d80b
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pymilvus/client/entity_helper.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,12 @@
import numpy as np
import ujson

from pymilvus.exceptions import MilvusException, ParamError
from pymilvus.exceptions import (
DataNotMatchException,
ExceptionsMessage,
MilvusException,
ParamError,
)
from pymilvus.grpc_gen import schema_pb2 as schema_types
from pymilvus.settings import Config

@@ -56,13 +61,19 @@ def entity_to_str_arr(entity: Any, field_info: Any, check: bool = True):


def convert_to_json(obj: object):
if isinstance(obj, dict):
for k, v in obj.items():
if not isinstance(k, str):
raise DataNotMatchException(message=ExceptionsMessage.JSONKeyMustBeStr)
if isinstance(v, np.ndarray):
obj[k] = v.tolist()
return ujson.dumps(obj, ensure_ascii=False).encode(Config.EncodeProtocol)


def convert_to_json_arr(objs: List[object]):
arr = []
for obj in objs:
arr.append(ujson.dumps(obj, ensure_ascii=False).encode(Config.EncodeProtocol))
arr.append(convert_to_json(obj))
return arr


1 change: 1 addition & 0 deletions pymilvus/exceptions.py
Original file line number Diff line number Diff line change
@@ -218,3 +218,4 @@ class ExceptionsMessage:
AmbiguousQueryFilterParam = (
"Ambiguous parameter, either ids or filter should be specified, cannot support both."
)
JSONKeyMustBeStr = "JSON key must be str."

0 comments on commit 6e6d80b

Please sign in to comment.