Skip to content

fix(typing): export SQLModelConfig and allow ConfigDict for model_config (#2091) - #2092

Open
DYNOSuprovo wants to merge 1 commit into
fastapi:mainfrom
DYNOSuprovo:fix/export-sqlmodel-config-and-model-config-typing
Open

DYNOSuprovo wants to merge 1 commit into
fastapi:mainfrom
DYNOSuprovo:fix/export-sqlmodel-config-and-model-config-typing

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

Summary

Fixes #2091.

Problem

In sqlmodel, SQLModelMetaclass declared model_config: SQLModelConfig.

  1. SQLModelConfig was only defined in sqlmodel._compat and was not re-exported by sqlmodel or sqlmodel.main, preventing users from publicly importing or referencing SQLModelConfig.
  2. Because SQLModelConfig inherits from Pydantic's BaseConfig/ConfigDict, assigning a standard Pydantic ConfigDict or a plain dictionary literal to model_config on an SQLModel subclass triggered strict type errors in type checkers such as Astral's ty:
    invalid-assignment: Object of type ConfigDict is not assignable to attribute model_config of type SQLModelConfig
    

Solution

  • Re-export SQLModelConfig and Pydantic's ConfigDict in sqlmodel and sqlmodel.main.
  • Widen SQLModelMetaclass.model_config annotation to SQLModelConfig | ConfigDict | dict[str, Any].
  • Add comprehensive unit tests in tests/test_pydantic/test_model_config.py verifying SQLModelConfig and ConfigDict public exports, type validity, and configuration behavior across models.

Verification

  • pytest tests/test_pydantic/test_model_config.py: 6 passed
  • ty check sqlmodel: 0 diagnostics
  • ty check tests/test_pydantic/test_model_config.py: 0 diagnostics
  • ruff check sqlmodel tests: passed
  • ruff format sqlmodel tests --check: 171 files left unchanged

@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

…fig (fastapi#2091)

Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
@DYNOSuprovo
DYNOSuprovo force-pushed the fix/export-sqlmodel-config-and-model-config-typing branch from 0b27188 to 46b8400 Compare September 22, 2026 14:26
@github-actions github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Sep 22, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants