Skip to content

fix(python): raise clear ValueError when vector column cannot be infe…#3567

Merged
wjones127 merged 3 commits into
lancedb:mainfrom
Vitaliy-Pikalo:fix/1653-raise-error-when-vector-column-not-inferred
Jul 17, 2026
Merged

fix(python): raise clear ValueError when vector column cannot be infe…#3567
wjones127 merged 3 commits into
lancedb:mainfrom
Vitaliy-Pikalo:fix/1653-raise-error-when-vector-column-not-inferred

Conversation

@Vitaliy-Pikalo

Copy link
Copy Markdown
Contributor

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.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added bug Something isn't working Python Python SDK labels Jun 22, 2026

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Vitaliy-Pikalo, thanks for submitting this PR. Could you add a unit test for this?

Comment thread python/python/lancedb/util.py Outdated
Comment on lines +308 to +310
try:
vector_column_name = inf_vector_column_query(
schema, dim=_query_vector_dim(query)
)
except Exception as e:
raise e
vector_column_name = inf_vector_column_query(
schema, dim=_query_vector_dim(query)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(blocking): Does inf_vector_column_query not raise an error anymore? This seems like a suspicious change worth clarifying.

@Vitaliy-Pikalo

Copy link
Copy Markdown
Contributor Author

@wjones127 The unit test is already in commit 25f8c65python/python/tests/test_util.py adds test_infer_vector_column_raises_clear_error. It creates a table with no vector column and asserts that search([1.0, 2.0]).to_list() raises a ValueError with a helpful message. (Also replied inline about the inf_vector_column_query error-handling question.)

@Vitaliy-Pikalo

Copy link
Copy Markdown
Contributor Author

wjones127 The unit test is already in commit 25f8c65 - python/python/tests/test_util.py adds test_infer_vector_column_raises_clear_error. It creates a table with no vector column and asserts that search([1.0, 2.0]).to_list() raises a ValueError with a helpful message. (Also replied inline about the inf_vector_column_query error-handling question.)

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, make sense. Looks good.

@wjones127

Copy link
Copy Markdown
Contributor

@Vitaliy-Pikalo it looks like your changes might actually be breaking several tests. Please take a look.

Vitaliy-Pikalo and others added 3 commits July 16, 2026 11:16
…rred

In `infer_vector_column_name`, when `query is None` and `query_type` is not "fts" or "hybrid", the function silently returned `None`. This `None` then propagated downstream causing a cryptic `TypeError`. Also removes the no-op `try/except Exception as e: raise e` wrapper around `inf_vector_column_query`. Fixes lancedb#1653.
… inferred

Added a regression test to ensure querying a table without an inferable vector column raises a clear ValueError instead of a TypeError.
infer_vector_column_name raised ValueError whenever vector_column_name
stayed None, including for plain scans (query is None, query_type not
"hybrid"). Those scans never attempt inference and previously returned
None as a no-op, so the new guard broke to_pandas()/to_arrow()/duckdb/
polars integrations and any other call to search() with no query.

Only raise when a vector search was actually requested and inference
failed.
@wjones127
wjones127 force-pushed the fix/1653-raise-error-when-vector-column-not-inferred branch from 25f8c65 to 3995729 Compare July 16, 2026 18:42
@wjones127
wjones127 merged commit 82906ec into lancedb:main Jul 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(python): failed to infer column name from the schema

2 participants