Repository navigation
Commit 457e12b
authored
Python: fix(sql_server): validate collection field types before table creation (#14697)
## 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 #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.1 parent 87eadc7 commit 457e12b
2 files changed
Lines changed: 45 additions & 7 deletions
File tree
- python
- semantic_kernel/connectors
- tests/unit/connectors/memory
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
799 | 800 | | |
800 | 801 | | |
801 | 802 | | |
802 | | - | |
| 803 | + | |
803 | 804 | | |
804 | 805 | | |
805 | 806 | | |
806 | 807 | | |
807 | 808 | | |
| 809 | + | |
808 | 810 | | |
809 | 811 | | |
810 | | - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
811 | 817 | | |
812 | 818 | | |
813 | 819 | | |
| |||
830 | 836 | | |
831 | 837 | | |
832 | 838 | | |
833 | | - | |
| 839 | + | |
834 | 840 | | |
835 | 841 | | |
836 | 842 | | |
837 | 843 | | |
838 | 844 | | |
839 | 845 | | |
840 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
841 | 851 | | |
842 | 852 | | |
843 | 853 | | |
| |||
886 | 896 | | |
887 | 897 | | |
888 | 898 | | |
889 | | - | |
| 899 | + | |
890 | 900 | | |
891 | 901 | | |
892 | 902 | | |
893 | 903 | | |
894 | 904 | | |
895 | | - | |
| 905 | + | |
896 | 906 | | |
897 | 907 | | |
898 | 908 | | |
| |||
993 | 1003 | | |
994 | 1004 | | |
995 | 1005 | | |
996 | | - | |
| 1006 | + | |
| 1007 | + | |
997 | 1008 | | |
998 | 1009 | | |
999 | 1010 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
162 | 189 | | |
163 | 190 | | |
164 | 191 | | |
| |||
0 commit comments