Repository navigation
Python: fix(sql_server): validate collection field types before table creation - #14697
Open
哈基米 (BlueX888) wants to merge 1 commit into
Open
哈基米 (BlueX888) wants to merge 1 commit into
哈基米 (BlueX888) wants to merge 1 commit into
Conversation
Automatic table creation for the SQL Server vector store interpolated the Python-to-SQL type mapping result directly into the CREATE TABLE statement. Unrecognized field types (for example datetime.date, Optional[str], or uuid.UUID) produced a literal None column type, so callers of ensure_collection_exists() got an opaque pyodbc syntax error from the database instead of a validation error. Raise VectorStoreModelValidationError from _python_type_to_sql() for unsupported field types, naming the field and the type, before any connection is acquired or SQL is executed — mirroring the validation the PostgreSQL connector already performs. Callers using unsupported types should create the table themselves, as documented for Postgres.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SQL Server vector store's type mapping (
_python_type_to_sql) returnedNonefor data fields with unmapped Python types — e.g.datetime.date,Optional[str],UUID— and the CREATE TABLE builder interpolated thatNonedirectly into the DDL, soensure_collection_existsfailed with an opaque pyodbc syntax error instead of telling the user what was wrong.Unmapped field types now raise
VectorStoreModelValidationErrorfrom the pure type-mapping helper, before any connection or SQL is built — the same behavior Postgres got in #14611. The error names the field and its unsupported type, and points at the escape hatch:Behavior notes
Optional[str]and similar optional-of-unmapped types are now rejected up front — the same trade-off Python: Validate PostgreSQL collection field types #14611 accepted for Postgres, where a clean early error beats a database-side failure with no actionable message.date→DATEetc. would be a feature decision); if maintainers want them they can layer them on top of the validation.Testing
python/tests/unit/connectors/memory/test_sql_server.py: parametrized unmapped-type cases (datetime.date,Optional[str],uuid.UUID,list[datetime.date]) and an unsupported key-field case, each asserting the validation error names the field and the type; the pre-existing exact-DDL happy-path tests are unchanged and pass.datetime.datefield reads[created] None NULL, and the new tests fail withDID NOT RAISE. Green with the fix: the wholeconnectors/memoryunit directory passes (546 tests), plus ruff and mypy clean on the changed file.