-
Notifications
You must be signed in to change notification settings - Fork 233
Environment variable names are converted to lower case #340
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
Comments
Yes this happens because Environment variables are converted to lower case but this is not the case for the rest of the file formats supported by the crate. |
Any update on this issue? I would also want the option not to convert env var into lowercase internally. |
@YounessBird yes please submit a PR and we go from there. |
@matthiasbeyer I have wrote a patch to fix this, however, it turns out it's not as straight forward as I first thought. config.toml FOO = "I should be overridden" main.rs #[derive(Debug, Deserialize,PartialEq)]
enum TestEnum {
FOO(String)
}
let cfg= Config::builder()
.add_source(File::new("config.toml", FileFormat::Toml)).build().unwrap();
let foo: TestEnum = cfg.try_deserialize().unwrap();
// Error the code won't work because all the keys inserted into the map are now lowercase, which means in the deserialization phase |
Leaving the case as is makes sense to me. It's easy enough to override the Rust warnings about identifier case, i.e. |
@pictographer Yes, that could also be easily fixed by matching for uppercase in the deserialization phase for enums. It will be awesome if the same can be done for structs but that will require a manual struct deserialization. Also as a side note I am not sure why the crate limits enums to deserialize for one field only. |
@pictographer you're referencing the config crate here? You realize that this is the codebase of the config crate? 😆
This. I am eager to do things the right way in the next generation of this crate (see #321) and not put too much effort into the existing code IF it turns out that the next generation will actually be delivered at some point. I still invite you all, though, to propose fixes or changes to the existing implementation, of course! |
Oops! I've gotta laugh. I wish my brain worked better. |
@matthiasbeyer, thank you for the careful work! Nice to see this merged. |
This is not a solution but some workaround that may help in same case. The idea is to create a new config from original config by overriding some of the values. It tries to find the real/fixed path for each value coming from the environment. To make it work the value have to be present on the config through a non-environment source to know the "correctly" cased path. Note - it was made in a hurry, so solution may contain bugs apart from the limitation.
|
Environment variable names are converted to lower case internally. This is surprising undocumented behavior. We want to be able to override values from a configuration file with environment variables. It would be natural to use the same spelling (not counting the prefix), but this doesn't work if the configuration file keys are upper case. To make it work, the configuration file keys must be lower case.
config.toml
In the shell
I was using TOML for the config file and bash for the shell, if it matters.
The text was updated successfully, but these errors were encountered: