Skip to content

fix overrides dropped when --multirun flag appears between them#3133

Open
Mr-Neutr0n wants to merge 1 commit into
facebookresearch:mainfrom
Mr-Neutr0n:fix-multirun-override-ordering
Open

fix overrides dropped when --multirun flag appears between them#3133
Mr-Neutr0n wants to merge 1 commit into
facebookresearch:mainfrom
Mr-Neutr0n:fix-multirun-override-ordering

Conversation

@Mr-Neutr0n

Copy link
Copy Markdown

When --multirun (or any optional flag) is placed between override arguments on the command line, argparse only sees the overrides before the flag and rejects the rest as unrecognized. For example:

python app.py task=1 --multirun db=mysql
# error: unrecognized arguments: db=mysql

This happens because nargs="*" positional args stop consuming tokens as soon as argparse encounters an optional flag. The overrides after the flag never get picked up.

Fixed by switching from parse_args() to parse_known_args() and merging any remaining tokens back into the overrides list. All orderings now work:

python app.py --multirun task=1 db=mysql    # works (already worked)
python app.py task=1 db=mysql --multirun    # works (already worked)
python app.py task=1 --multirun db=mysql    # works (was broken)

Fixes #3053

argparse's nargs='*' positional stops consuming tokens when it
hits an optional flag mid-sequence. so 'task=1 --multirun db=mysql'
would only see task=1 as an override and reject db=mysql.

switch to parse_known_args and merge leftover tokens back into the
overrides list. flag ordering no longer matters.

fixes facebookresearch#3053
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 15, 2026
@omry omry added the triage label May 16, 2026
@Mr-Neutr0n

Copy link
Copy Markdown
Author

Hi! Quick status: this still applies cleanly to the latest main as of today, and the PR is still mergeable. Re-requesting a review. If this looks good now, I would be happy to see it merged; if the repo has moved on, I am just as happy to close it.

@omry

omry commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks I'll get to it.

@omry omry removed the triage label Jun 7, 2026

@omry omry left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I agree this is a real CLI bug, and supporting overrides on both sides of --multirun is the right behavior.

Before merging, could you please make a few updates?

  1. Add a news fragment for the user-visible bugfix, e.g. news/3053.bugfix.

  2. Add an end-to-end regression test through an actual @hydra.main app invocation. The current parser-level test is useful, but the reported failure happens through the normal app path. It would be good to cover a command like:

    python app.py task=1 --multirun db=mysql
  3. Please preserve the existing unknown-option behavior. The current implementation switches from parse_args() to parse_known_args() and appends all remaining tokens to overrides. That fixes misplaced overrides, but it also means an unrelated unknown CLI option can make it into the overrides list and probably fail later, instead of failing immediately as an unrecognized argument. For example:

    python app.py task=1 --bad-flag db=mysql

    In the current PR, --bad-flag can be appended to overrides. This should continue to fail as an unknown CLI option during argument parsing. Unknown CLI options should fail predictably; only valid Hydra overrides that appear after known flags should be accepted.

Once those are covered, this looks like a good 1.4.0 bugfix candidate.

@omry omry added the awaiting_response Awaiting response label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting_response Awaiting response CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] --multirun yields error on specific command line flag ordering

2 participants