Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug where subcommands and config are affected by order #88

Closed
carmocca opened this issue Aug 24, 2021 · 2 comments
Closed

Bug where subcommands and config are affected by order #88

carmocca opened this issue Aug 24, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@carmocca
Copy link
Contributor

carmocca commented Aug 24, 2021

The order in which subcommands are added impacts the resulting config

Most likely a bug in 6530146

from jsonargparse import ArgumentParser, ActionConfigFile

parser = ArgumentParser(parse_as_dict=True)
parser.add_argument('--config', action=ActionConfigFile)
subcommands = parser.add_subcommands()

def fn(a=0, b=None):
    ...

subparser = ArgumentParser()
subparser.add_function_arguments(fn, fail_untyped=False)
subcommands.add_subcommand("cmd1", subparser)

subparser = ArgumentParser()
subparser.add_function_arguments(fn, fail_untyped=False)
subcommands.add_subcommand("cmd2", subparser)

cfg = {
    'cmd1': {'a': 1, 'b': 2},
    'cmd2': {'a': 3, 'b': 4}
}
config = parser.parse_args([f"--config={cfg}", "cmd1"])
print(config)
# {'config': [None], 'subcommand': 'cmd1', 'cmd1': {'a': 1, 'b': 2}}
config = parser.parse_args([f"--config={cfg}", "cmd2"])
print(config)
# {'config': [None], 'subcommand': 'cmd2', 'cmd1': {'a': 1, 'b': 2}, 'cmd2': {'a': 0}}

I think both cases should produce the expected config:

# {'config': [None], 'subcommand': <the-subcommand>, 'cmd1': {'a': 1, 'b': 2}, 'cmd2': {'a': 3, 'b': 4}}
@mauvilsa
Copy link
Member

Actually the idea was that only the settings for the selected subcommand would be kept. So the second case should have been {'config': [None], 'subcommand': 'cmd2', 'cmd2': {'a': 3, 'b': 4}}. Will check what went wrong.

@mauvilsa mauvilsa added the bug Something isn't working label Aug 24, 2021
@mauvilsa
Copy link
Member

This is now fixed in master.

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

No branches or pull requests

2 participants