FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✨ Add support for `Literal` types by nsaccente · Pull Request #1439 · fastapi/sqlmodel · GitHub

Repository navigation

✨ Add support for Literal types - #1439

Closed
nsaccente wants to merge 31 commits into
fastapi:mainfrom
nsaccente:bugfix-57/literal-satype
Closed

nsaccente wants to merge 31 commits into
fastapi:mainfrom
nsaccente:bugfix-57/literal-satype

Conversation

Copy link
Copy Markdown

This PR addresses issue 57. The original issue explains that attempting to use a Literal type annotation in a SQLModel raises a type error from issubclass. This is because Literal is not a class, but a typing._SpecialForm, so static funcs like isinstance and issubclass don't work with it.

The fix was pretty straightforward, I just added a check before an isinstance or issubclass would have been called that checks if type_ is Literal.

nsaccente changed the title Add check for Literal type annotation in get_sqlalchemy_type 🐛Add check for Literal type annotation in get_sqlalchemy_type Jul 24, 2025

Copy link
Copy Markdown
Author

I have no idea how to add the proper labels to this PR, it looks like the permissions aren't set up to allow me to.

YuriiMotov changed the title 🐛Add check for Literal type annotation in get_sqlalchemy_type 🐛 Fix TypeError for fields annotated with Literal Aug 5, 2025
YuriiMotov added the bug Something isn't working label Aug 5, 2025

This comment was marked as outdated.

YuriiMotov linked an issue Aug 5, 2025 that may be closed by this pull request
8 tasks done
YuriiMotov dismissed their stale review August 5, 2025 17:25

oh, wait...

Copy link
Copy Markdown
Member

@nsaccente, thanks for working on this!
This works, but could you please add a test?

Copy link
Copy Markdown
Author

@nsaccente, thanks for working on this! This works, but could you please add a test?

Sure. I'll try to get that done sometime this week.

github-actions Bot removed the waiting label Aug 6, 2025

Copy link
Copy Markdown
Author

I've been fighting with getting the tests to work. I've been able to get things to pass in some versions of python, but not others. Any guidance on how to run these CI tests locally?

svlandeg marked this pull request as draft August 22, 2025 12:12
svlandeg self-assigned this Aug 22, 2025
YuriiMotov removed their assignment Oct 1, 2025
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 26, 2025

This comment was marked as resolved.

github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Dec 26, 2025
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 28, 2025

This comment was marked as resolved.

1 similar comment

This comment was marked as resolved.

svlandeg self-assigned this Jan 13, 2026
github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Jan 27, 2026
svlandeg marked this pull request as draft January 27, 2026 10:09

svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I gave this some more thought and agree that this feature is more complex that it initially seemed. Just avoiding the crash when using Literal isn't sufficient: we also want to map to the right datatype ànd somehow respect the value restriction that the Literal definition presents.

Building on the changes by Yurii to identify all-bool or all-int columns, I've now also pushed another update that creates 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.

Having mixed types in a Literal is still not ideal. I wonder whether we should support it by just making it all str (as the PR does now), whether we should reject it entirely (by raising an exception) or whether there is some other way we could deal with this 🤔

@YuriiMotov: would love a review from you on this!

svlandeg marked this pull request as ready for review January 27, 2026 12:55
svlandeg requested a review from YuriiMotov January 27, 2026 12:55
svlandeg removed their assignment Jan 27, 2026
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 1, 2026

This comment was marked as outdated.

1 similar comment

This comment was marked as outdated.

nsaccente closed this Feb 1, 2026
svlandeg self-assigned this Feb 2, 2026

svlandeg commented Feb 2, 2026

Copy link
Copy Markdown
Member

Follow-up PR as this one has been closed (despite being actively worked on): #1736

svlandeg removed their assignment Feb 2, 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

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL