-
Notifications
You must be signed in to change notification settings - Fork 504
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
Dotenv::Railtie.overload
violates policy about env
files priority
#424
Comments
Guys, I read the source code and identified the same problem. This problem is without solution since January, 2021. Is there any preview about you will change that? I didn't see any Opened Pull Request about that. |
domcermak
added a commit
to domcermak/dotenv
that referenced
this issue
Jun 25, 2022
domcermak
added a commit
to domcermak/dotenv
that referenced
this issue
Jun 25, 2022
@feihokpai you can always go with a monkey patch just like we did in our project but I created a PR with a fix I would prefer so we can hopefully get it fixed. |
This was referenced Aug 11, 2022
feliperaul
pushed a commit
to feliperaul/dotenv
that referenced
this issue
Aug 31, 2023
Fixed in #460 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
.env.development
should have higher priority then.env
while usingDotenv::Railtie.overload
Actual behavior
#overload
method violates policy aboutenv
files priority.Let's say
RAILS_ENV=development
and there are files.env.development
and.env
in the rails root directory.Case of
#load
methodcalls
which calls
which calls
which calls
which uses the
||=
operator, so when it is used with files in order given bythen the
#load
method fulfills the priority policy mentioned in readme. So variables in.env.development
have higher priority then.env
. This is correct behaviour. Unlike the#overload
method, which I am going to describe now.Case of
#overload
methodcalls
which calls
which calls
which uses the
=
operator, so the ENV values are really overriden. But with the givendotenv_files
fromthis means, that variables from
.env
file have the highest priority, because they are processed after all other env files.This violates the policy about env files priority. It also violates the comment by the
#overload
method definition "Same asload
, but will override existing values inENV
".There is a test for the
#overload
method in rails_spec.rb on line 116.which confirms the priority policy is violated, because "overloads .env.test with .env". Which leaves me confused, because documentation says there is a priority policy, and then the test tests that the policy is being violated intentionally.
Expected solution
Change
#overload
method inDotenv::Railtie
fromto
or a change of documentation.
System configuration
dotenv version: 2.7.6
Rails version: 5.0.7.2
Ruby version: 2.6.6
The text was updated successfully, but these errors were encountered: