fix overrides dropped when --multirun flag appears between them#3133
fix overrides dropped when --multirun flag appears between them#3133Mr-Neutr0n wants to merge 1 commit into
Conversation
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
|
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. |
|
Thanks I'll get to it. |
omry
left a comment
There was a problem hiding this comment.
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?
-
Add a news fragment for the user-visible bugfix, e.g.
news/3053.bugfix. -
Add an end-to-end regression test through an actual
@hydra.mainapp 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
-
Please preserve the existing unknown-option behavior. The current implementation switches from
parse_args()toparse_known_args()and appends all remaining tokens tooverrides. 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-flagcan be appended tooverrides. 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.
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: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()toparse_known_args()and merging any remaining tokens back into the overrides list. All orderings now work:Fixes #3053