Skip to content

fix: pass through dropdown value when not in choices for cascading dropdowns (fixes #12246)#13031

Closed
aayushbaluni wants to merge 1 commit intogradio-app:mainfrom
aayushbaluni:fix/12246-dropdown-tab-choices
Closed

fix: pass through dropdown value when not in choices for cascading dropdowns (fixes #12246)#13031
aayushbaluni wants to merge 1 commit intogradio-app:mainfrom
aayushbaluni:fix/12246-dropdown-tab-choices

Conversation

@aayushbaluni
Copy link
Copy Markdown

Summary

Fixes #12246

When a parent dropdown (e.g. country) changes and triggers an update to a child dropdown (e.g. city), the child receives the previous value as input. The child's choices may have been updated from a previous response, causing preprocess to raise Value not in list of choices.

Root Cause

The Dropdown preprocess method raised an error when the incoming value was not in the current choices. In cascading dropdowns (country/city), when the user changes country, the frontend sends the old city value. The backend's child dropdown may already have the new country's cities as choices from a previous update. Preprocess rejected the stale value before the handler could process it.

Fix

Pass through the value to the handler when it is not in choices (single-value case). The handler can then return the updated component with the correct value.

Changes

  • gradio/components/dropdown.py: When value not in choices, pass through instead of raising (single-value case)
  • test/components/test_dropdown.py: Updated test to expect pass-through behavior

Made with Cursor

…opdowns (fixes #12246)

When a parent dropdown (e.g. country) changes and triggers an update to a child
dropdown (e.g. city), the child receives the previous value as input. The
child's choices may have been updated from a previous response, causing
preprocess to raise 'Value not in list of choices'. Pass through the value
to allow handlers to process stale values and return the updated component.
@freddyaboulton
Copy link
Copy Markdown
Collaborator

Hi @aayushbaluni The original issue was not reproducible in version 6. Please verify the issue exists before opening an ai-generated PR (and verify the ai's fix is actually applicable)

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.

Within a tab environment, a valid update of choices and value of a dropdown raises an error "is not in the list of choices"

2 participants