Skip to content
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

🐛 Fix enum type checks ordering in get_sqlalchemy_type #669

Merged
merged 3 commits into from
Oct 23, 2023

Conversation

tiangolo
Copy link
Member

@tiangolo tiangolo commented Oct 23, 2023

🐛 Fix enum type checks ordering in get_sqlalchemy_type

This continues the work in #442 by @pierrecdn as I can't push to the original branch, but it includes his commits. 🤓

pierrecdn and others added 3 commits September 9, 2022 00:10
When enum subclassing/mix-in[1] is used, especially to ensure compatibility
and produce correct OpenAPI specifications with FastAPI[2], SQLModel on its
side doesn't map to the correct SQLAlchemy type.

e.g.:
* `class Foo(Enum)` will work but won't allow a proper OpenAPI spec. to be
generated.
* `class Foo(str, Enum)` will fix the previous situation, but prevents
SQLModel to read and map the object from the DB (due to validation errors).

Changing ordering of checks to ensure that Enum subclasses are tested first.

[1] https://docs.python.org/3/library/enum.html#restricted-enum-subclassing
[2] https://fastapi.tiangolo.com/sq/tutorial/path-params/#create-an-enum-class
@tiangolo tiangolo merged commit d3261ca into main Oct 23, 2023
@tiangolo tiangolo deleted the pr/pierrecdn/442 branch October 23, 2023 09:22
@tiangolo
Copy link
Member Author

This will be available in the next release, 0.0.9. 🎉

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.

2 participants