-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Failure to check choice matches for options when using a configuration yaml or json file. #404
Comments
The "To reproduce" section above is empty. Was it lost by mistake? |
Yeah, sorry. Ended up hidden in a comment. Fixed now! PTAL |
Thank you for reporting! This is fixed in pull request #405. |
Hey! Thanks for the fix, it works perfectly now. Wondering if this is just a quick fix and will be investigated later, or is the best way to go about it? Given underlying argparse parser already handles choice validation and a bunch of other things with the referenced line of code in my issue, won't there be issues with the other things that argparse parser does? Haven't exactly checked on the other functionality of that line of code, so not sure about the exact problems that might arise. |
The thing is that The fix might not be ideal, but certainly good enough. The most important part is the added unit test to make sure there are no regressions. You are free dig into the code to see how to refactor and improve the code for the better. Also you could contribute by writing unit tests for more cases and maybe identify other unknown bugs. |
🐛 Bug report
Using a config file (yaml or json) skips the choice validation step for any other argument.
To reproduce
Expected behavior
The same script above shows the expected behavior as well. But what should happen is parser should throw an error stating that the given argument is not valid as it is not within the set of options given.
Environment
pip install jsonargparse[all]
): as in exampleMy initial suspicions are that this has to do with how config file arguments are parsed.
This line (calling a function from argparse which further down the line calls the choice validation function in argparse):
jsonargparse/jsonargparse/_core.py
Line 259 in 5fc8357
is on a high level responsible for choice validation. But, in the current code, the config argument parsing doesn't fill out the other fields before the validation work is handed over to argparse. So whatever arguments come from the config file are not at all choice checked. The current code does have choice checking but that is only for subcommands and not for '--arg' (not sure what to call them but the ones with dashes or just arguments). Hence, any choice arguments provided via a config file go under the radar and can potentially wreak havoc down the line.
The text was updated successfully, but these errors were encountered: