fix: make find_choice_label defensive against non-dict choices#3047
Merged
FrankApiyo merged 2 commits intomainfrom Apr 1, 2026
Merged
fix: make find_choice_label defensive against non-dict choices#3047FrankApiyo merged 2 commits intomainfrom
FrankApiyo merged 2 commits intomainfrom
Conversation
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.
kelvin-muchiri
approved these changes
Apr 1, 2026
…_label pyxform Option objects implement Mapping but are not dict instances, so isinstance(choice, dict) skipped them and returned raw values instead of labels.
5bf0254 to
d97bb86
Compare
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.
Summary
find_choice_labeldefensive against non-dict items in the choices list by adding anisinstancecheck, and usedict.get()instead of bracket access to preventKeyError/TypeErrorwhen choices are missing expected keysfind_choice_labelcovering all branches: matching, no match, empty list, non-dict items, missing keys, and first-match behaviorTest plan
TestFindChoiceLabeltests passtest_chart_toolstests still pass