mirror of
https://github.com/lancedb/lancedb.git
synced 2026-08-18 20:18:37 +00:00
fix(python): raise clear ValueError when vector column cannot be infe… (#3567)
## Summary Fixes #1653. `infer_vector_column_name` in `util.py` could silently return `None` when `query is None` and `query_type` is not `"fts"` or `"hybrid"`. This `None` then propagated into downstream code, causing a cryptic `TypeError: expected bytes, NoneType found` rather than a clear error message. ## Changes - **Removes the no-op `try/except Exception as e: raise e`** around `inf_vector_column_query` (it was catching and immediately re-raising without adding any value) - - **Adds a `None` guard** after the inference block: if `vector_column_name` is still `None` at this point, raise a clear `ValueError` pointing the user to pass `vector_column_name` explicitly ## Before / After **Before:** cryptic `TypeError: expected bytes, NoneType found` deep in schema lookup code **After:** ``` ValueError: No vector column found in the schema. Please specify the vector column name explicitly via the `vector_column_name` parameter. ``` --------- Co-authored-by: Will Jones <willjones127@gmail.com>
This commit is contained in:
@@ -307,13 +307,19 @@ def infer_vector_column_name(
|
||||
# FTS queries do not require a vector column
|
||||
return None
|
||||
|
||||
if query is not None or query_type == "hybrid":
|
||||
try:
|
||||
vector_column_name = inf_vector_column_query(
|
||||
schema, dim=_query_vector_dim(query)
|
||||
)
|
||||
except Exception as e:
|
||||
raise e
|
||||
if query is None and query_type != "hybrid":
|
||||
# No vector search was requested (e.g. a plain scan), so there's
|
||||
# nothing to infer.
|
||||
return None
|
||||
|
||||
vector_column_name = inf_vector_column_query(schema, dim=_query_vector_dim(query))
|
||||
|
||||
if vector_column_name is None:
|
||||
raise ValueError(
|
||||
"No vector column found in the schema. Please specify the "
|
||||
"vector column name explicitly via the `vector_column_name` "
|
||||
"parameter."
|
||||
)
|
||||
|
||||
return vector_column_name
|
||||
|
||||
|
||||
@@ -924,3 +924,23 @@ def test_sanitize_data_stream():
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
next(output)
|
||||
|
||||
|
||||
def test_infer_vector_column_raises_clear_error(tmp_path):
|
||||
"""Regression: querying a table with no inferable vector column should raise
|
||||
a clear ValueError, not a cryptic TypeError (issue #1653).
|
||||
|
||||
Previously, inf_vector_column_query silently returned None which then caused
|
||||
a confusing TypeError deep in schema lookup. The fix adds a ValueError guard
|
||||
so the user gets a direct, actionable error message.
|
||||
"""
|
||||
db = lancedb.connect(tmp_path)
|
||||
table = db.create_table(
|
||||
"no_vec",
|
||||
data=[{"id": 1, "text": "hello"}, {"id": 2, "text": "world"}],
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="vector"):
|
||||
# Plain vector search on a table with no vector column should raise
|
||||
# a clear ValueError, not a cryptic TypeError.
|
||||
table.search([1.0, 2.0]).to_list()
|
||||
|
||||
Reference in New Issue
Block a user