fix: validate query_params type (#351)

This commit is contained in:
Qinren Zhou
2026-04-20 10:54:06 +08:00
committed by GitHub
parent f0c8476372
commit c17bd8876e
4 changed files with 98 additions and 61 deletions
+16 -14
View File
@@ -13,28 +13,24 @@
# limitations under the License.
from zvec.typing import DataType, StatusCode, MetricType, QuantizeType
from distance_helper import *
from doc_helper import *
from fixture_helper import *
from params_helper import *
from zvec import StatusCode
from zvec.extension import QwenReRanker, RrfReRanker, WeightedReRanker
from zvec.model import Collection, Doc, VectorQuery
from zvec.model.param import (
CollectionOption,
InvertIndexParam,
HnswIndexParam,
FlatIndexParam,
IVFIndexParam,
HnswIndexParam,
HnswQueryParam,
InvertIndexParam,
IVFIndexParam,
IVFQueryParam,
)
from zvec.model.schema import FieldSchema, VectorSchema
from zvec.extension import RrfReRanker, WeightedReRanker, QwenReRanker
from distance_helper import *
from zvec import StatusCode
from distance_helper import *
from fixture_helper import *
from doc_helper import *
from params_helper import *
from zvec.typing import DataType, MetricType, QuantizeType, StatusCode
# ==================== helper ====================
@@ -848,6 +844,9 @@ class TestCollectionQuery:
@pytest.mark.parametrize("doc_num", [10])
@pytest.mark.parametrize("topk", [1024])
@pytest.mark.parametrize("filter", ["int32_field >= 3 and int32_field <= 7"])
@pytest.mark.parametrize(
"full_schema_new", [(True, True, HnswIndexParam())], indirect=True
)
def test_query_vector_with_HnswQueryParam_valid(
self,
full_collection_new: Collection,
@@ -916,6 +915,9 @@ class TestCollectionQuery:
@pytest.mark.parametrize("doc_num", [10])
@pytest.mark.parametrize("topk", [10])
@pytest.mark.parametrize("filter", ["int32_field >= 3 and int32_field <= 7"])
@pytest.mark.parametrize(
"full_schema_ivf", [(True, True, IVFIndexParam())], indirect=True
)
def test_query_vector_with_IVFQueryParam_valid(
self, full_collection_ivf: Collection, nprobe, doc_num, topk, filter
):
+9 -12
View File
@@ -13,7 +13,6 @@
# limitations under the License.
from __future__ import annotations
import pytest
import zvec
from zvec import (
@@ -23,15 +22,15 @@ from zvec import (
Doc,
FieldSchema,
HnswIndexParam,
IndexOption,
IndexType,
InvertIndexParam,
LogLevel,
LogType,
VectorSchema,
StatusCode,
IndexOption,
IndexType,
VectorQuery,
OptimizeOption,
StatusCode,
VectorQuery,
VectorSchema,
)
# ==================== Common ====================
@@ -469,10 +468,9 @@ class TestCollectionInsert:
vectors={"dense": [1 + 0.1] * 128, "sparse": {1: 1.0, 2: 2.0, 3: 3.0}},
)
with pytest.raises(ValueError) as e:
# ValueError: doc validate failed: field[id] is configured not nullable,
# but doc does not contain this field
# ValueError: Invalid doc: field[id] is required but not provided
test_collection.insert(doc)
assert "field[id] is configured not nullable" in str(e.value)
assert "field[id] is required but not provided" in str(e.value)
# without name
doc = Doc(
@@ -484,7 +482,7 @@ class TestCollectionInsert:
)
with pytest.raises(ValueError) as e:
test_collection.insert(doc)
assert "field[name] is configured not nullable" in str(e.value)
assert "field[name] is required but not provided" in str(e.value)
def test_collection_insert_with_nullable_true_field(self, test_collection):
# id, name's nullable == False
@@ -591,8 +589,7 @@ class TestCollectionUpdate:
fields={"id": None},
)
with pytest.raises(ValueError) as e:
# ValueError: doc validate failed: field[id] is configured not nullable,
# but doc does not contain this field
# ValueError: Invalid doc: field[id] is required but its value is null
collection_with_single_doc.update(doc)
doc = Doc(