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

Unexpected config error when a default config file is empty #367

Closed
victor-yon opened this issue Sep 1, 2023 · 5 comments · Fixed by #370
Closed

Unexpected config error when a default config file is empty #367

victor-yon opened this issue Sep 1, 2023 · 5 comments · Fixed by #370
Labels
bug Something isn't working

Comments

@victor-yon
Copy link

victor-yon commented Sep 1, 2023

🐛 Bug report

If at least one default_config_files is set and this file is empty, a TypeError: Unexpected config: is triggered on parser.parse_args(). Even if no argument is mandatory.

To reproduce

from jsonargparse import ArgumentParser

parser = ArgumentParser(default_config_files=['config.yaml'])
parser.add_argument("test", type=int, help="test", default=1)
cfg = parser.parse_args()
print(cfg.as_dict())

no 'config.yaml' file

python main.py
> {'test': 1}

Work as expected, no error

empty 'config.yaml' file

touch config.yaml
python main.py
> Unexpected config error:

Not empty 'config.yaml' file
Work as expected, no error

echo "test: 42" > config.yaml
python bug.py
> {'test': 42, '__default_config__': Path_fr(config.yaml, cwd=/Users/...)}

Expected behavior

I expect to have the same behavior between no configuration file and empty configuration file.
In the case where every argument are optional I don't expect to have an error.

In my case I wanted to generate this default configuration file as suggest in the document with:

python example.py --print_config > config.yaml

But an empty file is created before to run the script. Which trigger the issue mentioned above.

Environment

  • jsonargparse version: 4.24.0
  • Python version: 3.11.4
  • How jsonargparse was installed: pip install jsonargparse[signatures]~=4.24 docstring-parser~=0.15 PyYAML~=6.0 ruyaml~=0.91
  • OS: macOS 13.4.1
@victor-yon victor-yon added the bug Something isn't working label Sep 1, 2023
@mauvilsa
Copy link
Member

mauvilsa commented Sep 4, 2023

@victor-yon thank you for reporting!

You are right. The recommended steps to create a config should not fail just because default_config_files is used. This should be fixed.

mauvilsa added a commit that referenced this issue Sep 5, 2023
…les used due to the config file initially being empty (#367).
mauvilsa added a commit that referenced this issue Sep 5, 2023
…les used due to the config file initially being empty (#367).
@mauvilsa
Copy link
Member

mauvilsa commented Sep 5, 2023

@victor-yon I created pull request #370 fixing this. Please try it out.

@victor-yon
Copy link
Author

Hi, thank you for the fix. I can try next Monday, I don't have access to my computer before.

mauvilsa added a commit that referenced this issue Sep 6, 2023
…les used due to the config file initially being empty (#367).
@mauvilsa
Copy link
Member

mauvilsa commented Sep 6, 2023

Merged it since I wanted to create a release and this change was simple. You can test it next week with the released package. If there are issues, please comment here.

@victor-yon
Copy link
Author

I confirm that is working as expected with jsonargparse v4.24.1. Thank you.

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 a pull request may close this issue.

2 participants