Closed mknaw closed 5 months ago
Thanks @mknaw for reporting this.
It is because Dotenv source parses extra values(apple=incorrect
in your case) at the end and it will override the old value(foobar_apple=correct
).
I think we can change it to don't override the value but I am afraid it will break some user code that depends on this.
Hi,
I'd like to inquire about the intentionality of this dotenv loading behavior when
env_prefix
is set. Namely, even with anenv_prefix
set in the model config, it looks like we happily read values whose name matches the field names even when they are not prefixed:I see per the documentation:
Respectfully, reading such unprefixed value seems like a footgun to me (imagine e.g.
DEBUG
vsSOME_OTHER_THING__DEBUG
), especially since the env-sourced variables do not exhibit this behavior. Intuitively, I'd expect overall similar behavior for both sources.But, even if this load-all behavior is desired, should there at least be an effort to prefer the dotenv value whose prefix matches over that with no prefix? Without having looked at the actual parsing code, it appears the last entry currently wins, which can be seen by modifying the previous test:
Thanks in advance.