Skip to content

SQLModelConfig is not publicly exported while SQLModel annotates model_config with it, rejecting public ConfigDict/dict spelling under ty #2091

Description

@zkewal

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions