Skip to content

fix: ensure last-invoked option wins for shared dest names#3261

Closed
Dhi13man wants to merge 1 commit intopallets:mainfrom
Dhi13man:fix/multi-option-callback-override
Closed

fix: ensure last-invoked option wins for shared dest names#3261
Dhi13man wants to merge 1 commit intopallets:mainfrom
Dhi13man:fix/multi-option-callback-override

Conversation

@Dhi13man
Copy link

@Dhi13man Dhi13man commented Mar 12, 2026

Summary

  • When multiple options target the same parameter name (dest) and one uses a callback, the last option specified on the command line should win
  • Previously, --custom bar --fetch incorrectly returned the sentinel value ($_fetch) instead of the callback result (foo) because the parser's last-written value was read by the wrong parameter during processing
  • Filters param_order to keep only the last invocation per dest name, so overshadowed options process as uninvoked and the existing guard in handle_parse_result lets the winning value through

Closes #2786

Test plan

  • Added parametrized regression test test_dual_option_callback_last_wins covering all 5 cases:
    • --fetch alone → callback result
    • --custom bar alone → explicit value
    • --custom bar --fetch → last option wins (callback result)
    • --fetch --custom bar → last option wins (explicit value)
    • No args → None default
  • Full test suite passes (1325 passed, 0 failures)
  • Linted with ruff (check + format)

When multiple options target the same parameter name (dest), the parser
stores only the last-written value. Previously, processing order caused
earlier-invoked options to read the wrong value from opts, and the guard
in handle_parse_result prevented the correct (last-invoked) option from
overwriting ctx.params.

Filter param_order to keep only the last invocation per dest name so
overshadowed options process as uninvoked, falling through to defaults.
The existing guard then allows the winning option's value through.

Closes #2786

Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
@davidism davidism closed this Mar 12, 2026
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.

Multi-value options override the value returned from callback when not all specified

2 participants