Fix get_parameter_source() returning None in type.convert() and callbacks#3477
Closed
Priyanshu-byte-coder wants to merge 1 commit into
Closed
Conversation
…acks In 8.4.0, handle_parse_result() was refactored to defer ctx.set_parameter_source() until after process_value() to support feature-switch group arbitration (pallets#3403). This meant that ParamType.convert() and option callbacks called during process_value() saw None from ctx.get_parameter_source(), breaking any code that uses the source to distinguish user-set values from defaults. Fix: set the source early (immediately after consume_value), before process_value() is called. If the parameter subsequently loses the feature-switch arbitration, restore the winning parameter's source. This preserves the arbitration semantics while making the source queryable at the right time. Fixes pallets#3458
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
Fixes #3458
In 8.4.0,
handle_parse_result()was refactored to support feature-switch group arbitration (#3403). As part of that refactor,ctx.set_parameter_source()was moved to afterprocess_value()completes. This broke anyParamType.convert()implementation or option callback that callsctx.get_parameter_source(param.name)— they receivedNoneinstead of the actual source.This also causes pallets/flask#6025 (
FLASK_DEBUGenv var stopped working in click 8.4), where Flask's_set_debugcallback relies onget_parameter_source()to distinguish default values from user-set ones.Root cause
Fix
Set the source immediately after
consume_value(), beforeprocess_value()is called. If the parameter subsequently loses feature-switch arbitration (another parameter with a more explicit source already claimed the slot), restore the winner's source.The arbitration semantics for
ctx.paramsare unchanged.Test plan
test_get_parameter_source_available_in_type_convert— assertsconvert()seesDEFAULTfor default invocation andCOMMANDLINEfor CLI invocationtest_get_parameter_source_available_in_callback— same check for option callbackstest_parameter_sourceparametrized cases still pass