Skip to content

Python: fix(sql_server): validate collection field types before table creation - #14697

Open
哈基米 (BlueX888) wants to merge 1 commit into
microsoft:mainfrom
BlueX888:contrib/sqlserver-field-type-validation-parity
Open

哈基米 (BlueX888) wants to merge 1 commit into
microsoft:mainfrom
BlueX888:contrib/sqlserver-field-type-validation-parity

Conversation

@BlueX888

Copy link
Copy Markdown

Summary

The SQL Server vector store's type mapping (_python_type_to_sql) returned None for data fields with unmapped Python types — e.g. datetime.date, Optional[str], UUID — and the CREATE TABLE builder interpolated that None directly into the DDL, so ensure_collection_exists failed with an opaque pyodbc syntax error instead of telling the user what was wrong.

Unmapped field types now raise VectorStoreModelValidationError from 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:

SQL Server field type 'datetime.date' for field 'created' is not supported for automatic table creation. Use a supported Python type, or create the table before using the collection.

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.
  • No new type mappings were added (date → DATE etc. 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.
  • Red on main: the generated DDL for a datetime.date field reads [created] None NULL, and the new tests fail with DID NOT RAISE. Green with the fix: the whole connectors/memory unit directory passes (546 tests), plus ruff and mypy clean on the changed file.

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.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 09:09
@BlueX888
哈基米 (BlueX888) requested a review from a team as a code owner October 31, 2026 09:09

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 31, 2026

This branch was successfully deployed

1 active deployment
github-app-auth — 57da6d13 Deployed Oct 31, 2026 by BlueX888 via add_label #29518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants