fix(sqlalchemy): support values-based sa.Enum columns - #1169
Draft
aiolibsbot wants to merge 1 commit into
Draft
Conversation
A values-based Enum (sa.Enum("a", "b")) has no member class, so its
python_type is str. Iterating it to build SelectInput choices raised
TypeError: 'type' object is not iterable, crashing resource setup for
any model using this documented SQLAlchemy pattern.
Branch on enum_class: iterate the member class when present (id=value,
name=member name, unchanged), otherwise use the .enums string list.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1169 +/- ##
==========================================
+ Coverage 95.56% 95.66% +0.09%
==========================================
Files 21 21
Lines 2954 2976 +22
Branches 193 201 +8
==========================================
+ Hits 2823 2847 +24
+ Misses 105 103 -2
Partials 26 26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix a crash when an admin model uses a values-based
sa.Enumcolumn(e.g.
sa.Enum("active", "inactive")).Why
Values-based enums have no member class, so
sa.Enum.python_typeisstr. The SelectInput choice builder iteratedpython_typedirectly,raising
TypeError: 'type' object is not iterableand crashingSAResourceconstruction for a first-class, documented SQLAlchemypattern. Only class-based enums (
sa.Enum(MyEnumClass)) worked before.How
Branch on
sa.Enum.enum_class:enum_classset): iterate the member class —id= membervalue,
name= member name (unchanged, matches the JSON encoder whichemits
enum.value).enum_classis None): use theenumsstring list, witheach string as both
idandname.Testing
test_values_based_enum(reproduces the crash pre-fix) andtest_class_based_enum(regression guard for existing behavior).test_admin_viewfailure ispre-existing and unrelated (Broken tests #934).
Advances #666 (TODO cleanup).
Quality Report
Changes: 2 files changed, 42 insertions(+), 2 deletions(-)
Code scan: clean
Tests: failed (command not found)
Branch hygiene: clean
Generated by Kōan