← 返回首页
✨ Add support for Literal types by svlandeg · Pull Request #1736 · fastapi/sqlmodel · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

✨ Add support for Literal types#1736

Open
svlandeg wants to merge 6 commits into
fastapi:mainfrom
svlandeg:feat/literal
Open

✨ Add support for Literal types#1736
svlandeg wants to merge 6 commits into
fastapi:mainfrom
svlandeg:feat/literal

Conversation

Copy link
Copy Markdown
Member

svlandeg commented Feb 2, 2026
edited
Loading

Reconstructing PR #1439, as the original author has closed this PR but @YuriiMotov and I had actually spent quite a bit of time on this already (in fact, we had completely rewritten the PR at this point 🙈).

Let me recap the history:

  • Originally the PR was created to fix #57, i.e. ensure there is no crash when using a Literal type annotation with SQLModel.
  • The PR assumed that all Literal values were strings (thus creating a DB column with type string), which @tiangolo pointed out wouldn't be ideal because it would be unexpected for input like Literal[1, 2, 3].
  • Yurii then added some detection logic for all-int and all-bool cases, to at least set the DB column type correctly. But he also raised the question of data validation.
  • I then pushed another update to create SQL constraints for the values in the Literal. This way, the data can't get corrupted and the user won't receive values that don't match the expected Literal definition.
  • The question of having mixed types is still open-ended, we can resolve it by either (1) making all str as "best attempt", (2) reject the input entirely or (3) some other way I'm not seeing.

svlandeg added the feature New feature or request label Feb 2, 2026
svlandeg assigned svlandeg and unassigned svlandeg Feb 2, 2026
svlandeg marked this pull request as ready for review February 2, 2026 09:17
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026

This comment was marked as resolved.

svlandeg self-assigned this Feb 22, 2026
github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 24, 2026
svlandeg removed their assignment Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Variables with annotation of 'typing.Literal' causes a panic

2 participants

Footer

© 2026 GitHub, Inc.