From 82906ecfee5fd510bafc019898ed22a1154aeec5 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 17 Jul 2026 11:58:19 -0400 Subject: [PATCH] =?UTF-8?q?fix(python):=20raise=20clear=20ValueError=20whe?= =?UTF-8?q?n=20vector=20column=20cannot=20be=20infe=E2=80=A6=20(#3567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- python/python/lancedb/util.py | 20 +++++++++++++------- python/python/tests/test_util.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/python/python/lancedb/util.py b/python/python/lancedb/util.py index 6a5be99db..f582be7b4 100644 --- a/python/python/lancedb/util.py +++ b/python/python/lancedb/util.py @@ -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 diff --git a/python/python/tests/test_util.py b/python/python/tests/test_util.py index 7cb0ce448..a9b66b2dd 100644 --- a/python/python/tests/test_util.py +++ b/python/python/tests/test_util.py @@ -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()