Skip to content

fix: make find_choice_label defensive against non-dict choices#3047

Merged
FrankApiyo merged 2 commits intomainfrom
fix/find-choice-label-defensive-access
Apr 1, 2026
Merged

fix: make find_choice_label defensive against non-dict choices#3047
FrankApiyo merged 2 commits intomainfrom
fix/find-choice-label-defensive-access

Conversation

@FrankApiyo
Copy link
Copy Markdown
Member

Summary

  • Make find_choice_label defensive against non-dict items in the choices list by adding an isinstance check, and use dict.get() instead of bracket access to prevent KeyError/TypeError when choices are missing expected keys
  • Add comprehensive tests for find_choice_label covering all branches: matching, no match, empty list, non-dict items, missing keys, and first-match behavior

Test plan

  • Verify TestFindChoiceLabel tests pass
  • Verify existing test_chart_tools tests still pass

Use isinstance and dict.get() to prevent KeyError/TypeError when choices
contain non-dict items or are missing expected keys. Add comprehensive
tests covering all branches.
…_label

pyxform Option objects implement Mapping but are not dict instances,
so isinstance(choice, dict) skipped them and returned raw values
instead of labels.
@FrankApiyo FrankApiyo force-pushed the fix/find-choice-label-defensive-access branch from 5bf0254 to d97bb86 Compare April 1, 2026 13:06
@FrankApiyo FrankApiyo merged commit 7f6bc3c into main Apr 1, 2026
11 checks passed
@FrankApiyo FrankApiyo deleted the fix/find-choice-label-defensive-access branch April 1, 2026 13:23
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