Replies: 2 comments
|
Confirmed against
That leaves three spellings that work today: 1. The spelling sqlmodel itself uses (runtime-safe, private module): from sqlmodel._compat import SQLModelConfig
class WidgetPublic(SQLModel):
id: int
model_config = SQLModelConfig(from_attributes=True)Here the assigned value is the annotated type, so there is nothing for a checker to flag. 2. Keep the public from pydantic import ConfigDict
class WidgetPublic(SQLModel):
id: int
model_config = ConfigDict(from_attributes=True) # type: ignore[assignment]3. Avoid the attribute entirely if the flag is only needed in one place: Why ty complains on (2) and mypy does not: the base class annotates Minimal upstream fix I would suggest — export the same typed config the library already uses internally, in from sqlmodel._compat import SQLModelConfig as SQLModelConfigplus a small test asserting that |
|
I can confirm this issue as well. In my projects, I'm using I'd love for it to be moved to, or exposed from a more public location in the package's exports. But I'm open to whatever solution the maintainers might recommend. |
Uh oh!
There was an error while loading. Please reload this page.
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.All reactions