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
Looks like passing in multiple env files to Dotenv.load(files, overwrite:true) is not correctly overwriting values. It seems to me that when overwrite is true, the input files' order is reversed AND also keys are overwritten, which negates the overwriting. I think NOT reversing the file order would fix it.
Steps to reproduce
I have this issue in my Ruby on Jets project, but it can be reproduced with a simple CLI example.
.env.development has
FOO=123
.env.development.local has
FOO=abc
Running this command: dotenv -f '.env.development,.env.development.local' ruby -e "puts ENV['FOO']"
Correctly prints 123
Running this command: dotenv -o -f '.env.development,.env.development.local' ruby -e "puts ENV['FOO']"
Incorrectly prints 123
Expected behavior
I expect that overwriting would take the last value (ie abc).
Actual behavior
The -o option is not working, it effectively takes the first value set.
System configuration
dotenv version: 3.1.0
Rails version: n/a
Ruby version: 3.2.2
The text was updated successfully, but these errors were encountered:
@jmouka Unless I'm misunderstanding something, I think the current behavior is working as expected. You may just need to switch the order of the files.
Normally, dotenv's behavior is that the first file to set a varaible wins, so you would want to load the most specific files first, then shared or global files. For example:
$ dotenv -f .env.local,.env.global
With -o, you still pass the files in the same order, but the files will be evaluated in reverse order so the most specific file still wins.
$ dotenv -o -f .env.local,.env.global
Let me know if I'm missunderstandinng your question. See #460 for when this was last visited.
Looks like passing in multiple env files to Dotenv.load(files, overwrite:true) is not correctly overwriting values. It seems to me that when overwrite is true, the input files' order is reversed AND also keys are overwritten, which negates the overwriting. I think NOT reversing the file order would fix it.
Steps to reproduce
I have this issue in my Ruby on Jets project, but it can be reproduced with a simple CLI example.
.env.development has
.env.development.local has
Running this command:
dotenv -f '.env.development,.env.development.local' ruby -e "puts ENV['FOO']"
Correctly prints 123
Running this command:
dotenv -o -f '.env.development,.env.development.local' ruby -e "puts ENV['FOO']"
Incorrectly prints 123
Expected behavior
I expect that overwriting would take the last value (ie abc).
Actual behavior
The -o option is not working, it effectively takes the first value set.
System configuration
dotenv version: 3.1.0
Rails version: n/a
Ruby version: 3.2.2
The text was updated successfully, but these errors were encountered: