Skip to content

Commit 659f5e0

Browse files
Multi cherry picks from master branch (#1339)
- Fix possible KeyError if description is not set (#1328) - Fix error message when insert mismatch datatypes (#1333) See also: #1324 Signed-off-by: yangxuan <[email protected]> Co-authored-by: wayblink <[email protected]>
1 parent 0e327b2 commit 659f5e0

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

pymilvus/orm/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ def to_dict(self):
166166

167167

168168
class FieldSchema:
169-
def __init__(self, name, dtype, description="", **kwargs):
169+
def __init__(self, name: str, dtype: DataType, description="", **kwargs):
170170
self.name = name
171171
try:
172-
DataType(dtype)
172+
dtype = DataType(dtype)
173173
except ValueError:
174174
raise DataTypeNotSupportException(message=ExceptionsMessage.FieldDtype) from None
175175
if dtype == DataType.UNKNOWN:
@@ -224,7 +224,7 @@ def construct_from_dict(cls, raw):
224224
kwargs['is_primary'] = raw.get("is_primary", False)
225225
if raw.get("auto_id", None) is not None:
226226
kwargs['auto_id'] = raw.get("auto_id", None)
227-
return FieldSchema(raw['name'], raw['type'], raw['description'], **kwargs)
227+
return FieldSchema(raw['name'], raw['type'], raw.get("description", ""), **kwargs)
228228

229229
def to_dict(self):
230230
_dict = {
@@ -285,7 +285,7 @@ def params(self):
285285
return self._type_params
286286

287287
@property
288-
def dtype(self):
288+
def dtype(self) -> DataType:
289289
return self._dtype
290290

291291

tests/test_schema.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import numpy
22
import pytest
33

4-
from pymilvus import CollectionSchema, FieldSchema, DataType
4+
from pymilvus import CollectionSchema, FieldSchema, DataType, MilvusException
55
from utils import *
6+
from pymilvus.orm import schema as s
67

78

89
class TestCollectionSchema:
@@ -143,3 +144,23 @@ def test_to_dict(self, raw_dict_norm, raw_dict_float_vector, raw_dict_binary_vec
143144
# for f in fields:
144145
# if f.dtype == DataType.FLOAT_VECTOR:
145146
# assert f.dim == len(dataframe1['float_vec'].values[0])
147+
148+
class TestCheckInsertDataSchema:
149+
def test_check_insert_data_schema_issue1324(self):
150+
schema = CollectionSchema([
151+
FieldSchema(name="id", dtype=DataType.INT64, descrition="int64", is_primary=True, auto_id=True),
152+
FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, descrition="float vector", dim=2),
153+
FieldSchema(name="work_id2", dtype=5, descrition="work id"),
154+
FieldSchema(name='path', dtype=DataType.VARCHAR, description='path to image', max_length=200),
155+
FieldSchema(name="uid", dtype=DataType.INT64, descrition="user id"),
156+
])
157+
158+
data = [
159+
[[0.003984056, 0.05035976]],
160+
['15755403'],
161+
['https://xxx.com/app/works/105149/2023-01-11/w_63be653c4643b/963be653c8aa8c.jpg'],
162+
['105149'],
163+
]
164+
165+
with pytest.raises(MilvusException):
166+
s.check_insert_data_schema(schema, data)

0 commit comments

Comments
 (0)