Skip to content

🐛 Fix TypeError for fields annotated with Literal #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nsaccente
Copy link

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 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
@nsaccente
Copy link
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 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 YuriiMotov added the bug Something isn't working label Aug 5, 2025
YuriiMotov

This comment was marked as outdated.

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

oh, wait...

@YuriiMotov
Copy link

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

@nsaccente
Copy link
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 github-actions bot removed the waiting label Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
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