fix(python): handle missing query-by-id documents (#519)
This commit is contained in:
parent
9bd0c6eea9
commit
4292bd337d
|
|
@ -300,3 +300,16 @@ class TestQueryExecutor:
|
|||
results = executor._execute_python_pipeline(vectors, collection)
|
||||
assert results == [["raw1"], ["raw2"]]
|
||||
assert collection.Query.call_count == 2
|
||||
|
||||
def test_build_search_query_by_missing_id_raises_value_error(self):
|
||||
vector_schema = VectorSchema(name="test", data_type=DataType.VECTOR_FP32)
|
||||
schema = CollectionSchema(name="test_collection", vectors=[vector_schema])
|
||||
executor = QueryExecutor(schema)
|
||||
ctx = QueryContext(topk=5)
|
||||
collection = MagicMock()
|
||||
collection.Fetch.return_value = {}
|
||||
|
||||
with pytest.raises(ValueError, match="Document with id 'missing' not found"):
|
||||
executor._build_search_query(
|
||||
ctx, Query(field_name="test", id="missing"), collection
|
||||
)
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ class QueryExecutor:
|
|||
vec_data = query.vector
|
||||
elif query.has_id():
|
||||
fetched = collection.Fetch([query.id])
|
||||
doc = next(iter(fetched.values()))
|
||||
doc = next(iter(fetched.values()), None)
|
||||
if not doc:
|
||||
raise ValueError(f"Document with id '{query.id}' not found")
|
||||
vec_data = doc.get_any(vector_schema.name, vector_schema.data_type)
|
||||
|
|
|
|||
Loading…
Reference in New Issue