Fix: Environment variables do not overwrite Config.toml options #2433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #2429
This is my first PR on this project and it turned out a bit bigger than expected. So I am not sure about some of the decisions I made.
separator("_")
from the Environment source setup, because this is intended for nested structures.convert_case(Case::Kebab)
to the Environment source setup to match the casing serde expects."[leptos-options]"
from toml string to let the settings be parsed as root level, otherwise the settings from the file and the ones set by the environment variables would be considered in different structures, therefore not affecting each other. Because of thisget_config_from_str()
now returns aLeptosOptions
object instead of aConfFile
.The test cases gave me some troubles as I had some inconsistent results. I assume (because tests are executed in parallel) that sometimes variables set in one test could interfere with a test that does not expect them (now that they could actually overwrite settings originated from a file source).
I added
temp-env
as a dev dependency to address my issues. Afterwards the tests were working consistently again and I added a new test to explicitly test the override functionality.Because I changed the parsing from
ConfFile
toLeptosOptions
, I think theserde::Deserialize
trait could actually be removed from theConfFile
struct. Any opinions on that?