Skip to content

Conversation

@harryswift01
Copy link
Contributor

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:

  • Compare CLI arguments against argparse’s default values parse_args([]) to correctly detect which values were explicitly set by the user.
  • Apply YAML values only if the CLI has not explicitly overridden them.
  • Ensure default values are only used when both CLI and YAML are absent.

Improve merging logic in merge_configs():

  • Prevent YAML values from being ignored when CLI inputs are not explicitly provided.
  • Maintain correct priority order: CLI > YAML > Defaults.

Enhance logging for debugging:

  • Log when values are being overridden by CLI or YAML.
  • Improve debugging output to track final argument values after merging.

Impact

  • Ensures CLI arguments always take priority over YAML and default values.
  • Fixes cases where YAML inputs were incorrectly ignored.
  • Improves reliability of configuration handling.
  • Provides better logging for debugging configuration issues.

- 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
@harryswift01 harryswift01 added the bug Something isn't working label Mar 26, 2025
@harryswift01 harryswift01 added this to the WP4 - Input/Output milestone Mar 26, 2025
@harryswift01 harryswift01 requested a review from jimboid March 26, 2025 14:42
@harryswift01 harryswift01 self-assigned this Mar 26, 2025
Copy link
Member

@jimboid jimboid left a comment

Choose a reason for hiding this comment

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

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.

@harryswift01 harryswift01 merged commit e04dad2 into main Mar 26, 2025
6 checks passed
@harryswift01 harryswift01 deleted the 75-default-override-bug branch March 26, 2025 15:03
@harryswift01 harryswift01 linked an issue Mar 26, 2025 that may be closed by this pull request
@jimboid jimboid modified the milestones: WP4 - Input/Output, 1.0.0 release Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defaults over riding YAML inputs

3 participants