You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usage: main.py [-h] [--config CONFIG] [--print_config[=flags]] [--b.help [CLASS_PATH_OR_NAME]] b
error: Validation failed: Key "b" is required but not included in config object or its value is None.
I can instantiate this class with:
export FOO_B="{v: 1}"
python -m main
But I cannot even override v:
export FOO_B__V=2
python -m main
Will still result in v being 1.
Expected behavior
I can instantiate a class from env variables. At least override fields.
Environment
jsonargparse version: 4.37.0
Python version: 3.12.8
How jsonargparse was installed: uv pip install -U "jsonargparse[all]"
OS: macOS
The text was updated successfully, but these errors were encountered:
Note that not every possible name for environment variables is supported. And this wouldn't be considered a bug. In principle you should look at the output of --help to know what environment variable names you can use.
In this particular case b is a subclass type. So Bar or a subclass of Bar is accepted. And there is no guarantee that all subclasses have v. For command line arguments now the base class is implicitly chosen when an init arg that matches is given. This case looks similar but for env vars. But env vars are different because they don't have an order. Right now I am not sure if FOO_B__V should be supported in this case.
On a different note, since parameter b doesn't have a default, it becomes positional. But a subclass as positional is not really a use case. And I have noted that as positional, the output of --help doesn't show the env var FOO_B. Better to implement this as CLI(main, default_env=True, env_prefix="FOO", as_positional=False).
🐛 Bug report
Cannot instantiate a class from env variables.
To reproduce
In
main.py
:In shell:
export FOO_B__V=2 python -m main
Will result in the error:
I can instantiate this class with:
But I cannot even override
v
:export FOO_B__V=2 python -m main
Will still result in
v
being 1.Expected behavior
I can instantiate a class from env variables. At least override fields.
Environment
uv pip install -U "jsonargparse[all]"
The text was updated successfully, but these errors were encountered: