Skip to content

fix: Populate possible_values and set data_type='Enum' for enum variables#91

Merged
anth-volk merged 1 commit intoapp-v2-migrationfrom
fix/enum-possible-values-v2
Mar 4, 2026
Merged

fix: Populate possible_values and set data_type='Enum' for enum variables#91
anth-volk merged 1 commit intoapp-v2-migrationfrom
fix/enum-possible-values-v2

Conversation

@SakshiKekre
Copy link
Contributor

Summary

  • Populates possible_values field with JSON-encoded values when a variable has enumerated options
  • Sets data_type to "Enum" for variables with possible_values, enabling frontend dropdowns
  • Fixes the issue where state_name and other enum variables rendered as text inputs instead of dropdowns

Context

The frontend's VariableInput.tsx only renders a <Select> dropdown when data_type === "Enum". Previously, enum variables had their Python type name (e.g., "str") as data_type, causing text inputs to render instead.

Test plan

  • Re-seed database and verify state_name variable has data_type: "Enum" and possible_values: ["AL", "AK", ...]
  • Verify frontend renders state dropdown in household builder

🤖 Generated with Claude Code

@SakshiKekre SakshiKekre force-pushed the fix/enum-possible-values-v2 branch 2 times, most recently from 2338a5a to 0fe6cd9 Compare March 3, 2026 14:43
@SakshiKekre
Copy link
Contributor Author

⚠️ Dependency: This PR depends on #92 being merged first.

Background: The app-v2-migration branch has failing tests due to direct commits that added country_id to computation module functions without updating tests. PR #92 fixes those tests.

Merge order:

  1. Merge fix: Update computation module tests for country_id parameter #92 (test fix)
  2. Rebase this PR on updated app-v2-migration
  3. Then this PR will pass CI

@SakshiKekre SakshiKekre requested a review from anth-volk March 3, 2026 15:19
@anth-volk
Copy link
Contributor

@SakshiKekre Just merged #92. Could you rebase and merge?

@SakshiKekre SakshiKekre force-pushed the fix/enum-possible-values-v2 branch from 0fe6cd9 to db3c6e9 Compare March 3, 2026 18:30
@anth-volk
Copy link
Contributor

@SakshiKekre please confirm that the app-v2-migration branch already properly serialized and deserializes into/out of this structure, e.g., when displaying the param setter. If it doesn't, please also add that handling to this PR.

@SakshiKekre
Copy link
Contributor Author

@anth-volk Thanks for the merge.
And yes, I confirmed that serialization/deserialization works correctly:

  • Serialization (API -> DB): Our fix in seed_models.py uses json.dumps() to write possible_values as JSON for PostgreSQL COPY
  • Deserialization (DB -> API): Already handled by sa_column=Column(JSON) in models/variable.py - SQLAlchemy auto-converts JSONB -> Python list

@anth-volk
Copy link
Contributor

@SakshiKekre Sorry, can you fully rebase all of this again? Made some changes to fix a couple bugs and improve code quality.

…bles

When a variable has possible_values (from policyengine), populate the
possible_values field with JSON-encoded values and set data_type to "Enum".
This allows the frontend to render dropdowns for enum variables like state_name.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@SakshiKekre SakshiKekre force-pushed the fix/enum-possible-values-v2 branch from db3c6e9 to 4f29c96 Compare March 4, 2026 08:07
@SakshiKekre
Copy link
Contributor Author

@anth-volk Thanks for the heads up. Rebased, good to go now.

@anth-volk anth-volk merged commit 2dc1bee into app-v2-migration Mar 4, 2026
1 check passed
@anth-volk anth-volk deleted the fix/enum-possible-values-v2 branch March 4, 2026 21:12
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