Conversation
- Fixed issue where CLI arguments were mistakenly overridden by YAML values - Correctly detect CLI-provided arguments by comparing them against argparse’s default values (`parse_args([])`) - Apply YAML values only if the argument wasn’t explicitly set via CLI - Ensure default values are used only if both CLI & YAML lack input - Now, CLI arguments always take priority over YAML and defaults - YAML values are applied when CLI doesn’t explicitly override them - Defaults are only used as a last resort - Fixes YAML being ignored in some cases, ensuring argument merging follows the correct hierarchy
jimboid
approved these changes
Mar 26, 2025
Member
jimboid
left a comment
There was a problem hiding this comment.
From the code this looks like it now has the correct flow. Argparse is initialised in a custom way so as to not treat defaults on the CLI as if they have been set. This then flows that any yaml files are set to args first, then any defaults pulled in to complete the args setup. This then has a hard override for params explicitly set on the CLI. It should be fairly trivial to create tests to ensure this remains the case, but the code looks correct. I the bug was reproduced and then shown by execution to be fixed then happy to merge PR.
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
In this PR, the argument merging logic is fixed to ensure the correct precedence: CLI > YAML > Defaults. Previously, YAML values were sometimes ignored due to argparse defaults being mistakenly treated as explicit CLI inputs. This PR ensures that CLI arguments take priority, YAML fills in missing values, and defaults are used only as a last resort.
Changes
Fix argument precedence handling:
parse_args([])to correctly detect which values were explicitly set by the user.Improve merging logic in
merge_configs():Enhance logging for debugging:
Impact