SQLModel annotates model_config: SQLModelConfig (sqlmodel/main.py), but SQLModelConfig lives in the private sqlmodel._compat module and is not exported from sqlmodel.__init__. As a result, typed application models cannot satisfy the annotation with any public spelling: ty rejects both the plain-dict and the pydantic ConfigDict forms, while mypy accepts both.
Environment: pinned sqlmodel 0.0.38 (latest checked 0.0.42), pydantic 2.13.4, ty 0.0.80.
Evidence:
sqlmodel/_compat.py defines class SQLModelConfig(BaseConfig, total=False) where BaseConfig = ConfigDict, adding table and registry keys.
from sqlmodel import SQLModelConfig raises ImportError; only from sqlmodel._compat import SQLModelConfig works.
- ty 0.0.80 reports
invalid-assignment for both model_config = {"from_attributes": True} (dict[str, bool] vs SQLModelConfig) and model_config = ConfigDict(from_attributes=True) (ConfigDict vs SQLModelConfig).
- mypy 1.20.2 reports no issues for either spelling.
Minimal reproduction (any non-table response model):
from pydantic import ConfigDict
from sqlmodel import Field, SQLModel
class Widget(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
class WidgetPublic(SQLModel):
id: int
model_config = ConfigDict(from_attributes=True)
Run ty check on the file: invalid-assignment on the model_config line. Replace with the plain-dict form and the same error appears with dict[str, bool]. mypy is clean in both cases.
Requested fix: either export SQLModelConfig from sqlmodel.__init__ (so apps can use the same spelling sqlmodel itself uses at main.py), or align the public model_config annotation so the documented public ConfigDict/dict spellings type-check. Happy to test a patch against ty 0.0.80.
SQLModel annotates
model_config: SQLModelConfig(sqlmodel/main.py), butSQLModelConfiglives in the privatesqlmodel._compatmodule and is not exported fromsqlmodel.__init__. As a result, typed application models cannot satisfy the annotation with any public spelling: ty rejects both the plain-dict and the pydanticConfigDictforms, while mypy accepts both.Environment: pinned sqlmodel 0.0.38 (latest checked 0.0.42), pydantic 2.13.4, ty 0.0.80.
Evidence:
sqlmodel/_compat.pydefinesclass SQLModelConfig(BaseConfig, total=False)whereBaseConfig = ConfigDict, addingtableandregistrykeys.from sqlmodel import SQLModelConfigraises ImportError; onlyfrom sqlmodel._compat import SQLModelConfigworks.invalid-assignmentfor bothmodel_config = {"from_attributes": True}(dict[str, bool]vsSQLModelConfig) andmodel_config = ConfigDict(from_attributes=True)(ConfigDictvsSQLModelConfig).Minimal reproduction (any non-table response model):
Run
ty checkon the file:invalid-assignmenton themodel_configline. Replace with the plain-dict form and the same error appears withdict[str, bool]. mypy is clean in both cases.Requested fix: either export
SQLModelConfigfromsqlmodel.__init__(so apps can use the same spelling sqlmodel itself uses at main.py), or align the publicmodel_configannotation so the documented publicConfigDict/dict spellings type-check. Happy to test a patch against ty 0.0.80.