-
Notifications
You must be signed in to change notification settings - Fork 24
Lack of .env files in config/** reverts any .env.#{environment} #13
Comments
+1 I can see the same behaviour. Settings defined in /.env file are overriding whatever is set in the /.env.test when running tests. |
+1 We found the same issue. We noticed that Rails is defined, but Rails.root is empty. This means that the pattern passed to Dir.glob is Our planned workaround is to drop |
Found this same issue. I am working on a rails project where we have both dotenv and dotenv-deployment in place. We have a When the initializer for # from: dotenv-deployment-0.0.2/lib/dotenv/deployment/deployment.rb
# lines 9-13
# Override any existing variables if an environment-specific file exists
if environment = ENV['RACK_ENV'] || (defined?(Rails) && Rails.env)
Dotenv.overload ".env.#{environment}"
Dotenv.overload *Dir.glob("#{Rails.root}/config/**/*.env.#{environment}") if defined?(Rails)
end This happens because the # from: dotenv-0.11.1/lib/dotenv.rb
# lines 21-29
def self.with(*filenames, &block)
filenames << '.env' if filenames.empty?
filenames.inject({}) do |hash, filename|
filename = File.expand_path filename
hash.merge(block.call(filename) || {})
end
end Although it makes sense that @bkeepers Would you support a pull request that would not include |
👍 |
1 similar comment
👍 |
Pull request opened bkeepers/dotenv#133 |
👍 |
+1 👍 |
+1 |
@surfacedamage's analysis is correct. same issue over here. |
Still not fixed? |
This doesn't occur in versions of dotenv before this gem was created, so you may be able to use something like |
In a Rails app, if there are no
.env
files inconfig/**/
,dotenv
adds (and parses) the root.env
file, reverting any overrides in.env.#{environment}
For example:
The
glob
call returns an empty array which is then backfilled with.env
inDotenv#with
. This means that the non-environment specific file is not only parsed twice, it reverts anything that is overridden in.env.development
The text was updated successfully, but these errors were encountered: