Skip to content

AI spam#3543

Closed
Xavrir wants to merge 1 commit into
pallets:mainfrom
Xavrir:fix-2786-shared-name-callback-override
Closed

AI spam#3543
Xavrir wants to merge 1 commit into
pallets:mainfrom
Xavrir:fix-2786-shared-name-callback-override

Conversation

@Xavrir
Copy link
Copy Markdown

@Xavrir Xavrir commented Jun 1, 2026

When several options share the same parameter name (a "feature-switch"
group, e.g. a plain --custom plus a flag_value --fetch that maps to the
same function argument), invoking only one of them produced the wrong value.

The parser stores command-line values keyed by the shared name. Because
options the user did not give are processed last, the un-invoked option read
the sibling's parsed value out of the parser results and overwrote the value
the invoked option's callback had already produced — so --fetch alone
yielded the raw sentinel instead of the callback's result.

This change tracks the parameters the parser actually saw
(Context._invoked_params) and, in Parameter.consume_value, skips adopting a
command-line value when this option was not invoked but a sibling sharing its
name was. The un-invoked option falls back to its own envvar/default.

This also fixes the secondary report: the "callback on both options" workaround
no longer calls the callback twice.

fixes #2786

Checklist (CONTRIBUTING.rst)

  • Added a regression test that fails without the change
    (tests/test_options.py::test_flag_value_group_callback_not_overridden).
  • Added a CHANGES.rst entry under the unreleased 8.5.0 section.
  • Code-level comments added referencing the issue. (No public API/docstring
    change, so no .. versionchanged:: needed.)
  • Full test suite passes locally (1669 passed, 24 skipped, 1 xfailed).

AI usage disclosure

This change was prepared with the assistance of an AI coding agent; the diagnosis,
patch, and regression test were reviewed and verified locally by the author.

When multiple options share a parameter name (a feature-switch group),
an option that was not invoked on the command line read its sibling's
parsed value out of the parser results and, because unspecified options
are processed last, overwrote the value the invoked option's callback
had already produced.

Track the parameters actually seen by the parser (Context._invoked_params)
and skip adopting a command-line value in consume_value when this option
was not invoked but a sibling sharing its name was. The un-invoked option
now falls back to its own envvar/default instead.

Adds a regression test and a CHANGES entry.

fixes pallets#2786

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@davidism davidism closed this Jun 1, 2026
@davidism davidism changed the title Preserve callback value for shared-name option groups AI spam Jun 1, 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