Skip to content

fix(sqlalchemy): support values-based sa.Enum columns - #1169

Draft
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/fix-values-based-enum
Draft

fix(sqlalchemy): support values-based sa.Enum columns#1169
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/fix-values-based-enum

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What

Fix a crash when an admin model uses a values-based sa.Enum column
(e.g. sa.Enum("active", "inactive")).

Why

Values-based enums have no member class, so sa.Enum.python_type is
str. The SelectInput choice builder iterated python_type directly,
raising TypeError: 'type' object is not iterable and crashing
SAResource construction for a first-class, documented SQLAlchemy
pattern. Only class-based enums (sa.Enum(MyEnumClass)) worked before.

How

Branch on sa.Enum.enum_class:

  • class-based (enum_class set): iterate the member class — id = member
    value, name = member name (unchanged, matches the JSON encoder which
    emits enum.value).
  • values-based (enum_class is None): use the enums string list, with
    each string as both id and name.

Testing

  • New test_values_based_enum (reproduces the crash pre-fix) and
    test_class_based_enum (regression guard for existing behavior).
  • Full suite: 99 passed, 1 xfailed. The lone test_admin_view failure is
    pre-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

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

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.66%. Comparing base (2448fd1) to head (b950470).
⚠️ Report is 168 commits behind head on master.

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              
Flag Coverage Δ
integration 80.84% <33.33%> (-0.12%) ⬇️
js 83.89% <ø> (ø)
unit 97.60% <100.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant