Closed tmaier closed 3 years ago
Issue opened at wrong repository. Closing it in favour of https://github.com/DatabaseCleaner/database_cleaner-active_record/issues/51
This is actually the correct place! The safeguard lives in core, so it can be shared by all adapters.
@tmaier Hmm. The safeguards are still in place, and should be working. I'm guessing its something specific to your usage of database cleaner, plus some refactoring that I did, and together they are having some unintended consequences.
Can you reduce your project down to a minimum reproduction of this issue, and share it with me? If I can reproduce it, I can fix it!
I had something similar happening here. The error was happening right at the require
line, so the code didn't yet had the time to reach the allow_remote_database_url
config. Changing to the env var strategy (i.e. exporting DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
) worked for me.
Here's the stack:
DatabaseCleaner::Safeguard::Error::RemoteDatabaseUrl:
ENV['DATABASE_URL'] is set to a remote URL. Please refer to https://github.com/DatabaseCleaner/database_cleaner#safeguards
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:45:in `run'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `block in run'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `each'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `run'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaner.rb:31:in `initialize'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:41:in `new'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:41:in `add_cleaner'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `block in []'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `fetch'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `[]'
# /home/xxxxxxxxxxx/.rvm/gems/ruby-2.7.1@xxxxxxxxxxxxxxxxxx/gems/database_cleaner-sequel-2.0.0/lib/database_cleaner/sequel.rb:7:in `<top (required)>'
# ./spec/spec_helper.rb:35:in `require'
spec_helper.rb:35 is require "database_cleaner/sequel"
.
We're seeing a similar thing happening when we run assets:precompile
, because that causes config/application.rb
to be loaded, which calls Bundler.require(*Rails.groups)
-- simply loading the gem triggers this exception, even if the process never calls it, so there's no way of configuring the DatabaseCleaner
class to turn off this safeguard.
I tried to configure it right after the Bundler.require
statement in the application.rb
. This did not fix the problem.
So I agree with @jcoglan.
Okay, opened #673 to attempt to fix this bug. Can you folks try out the branch and let me know if it fixes your issues?
You can do this by changing the database_cleaner line in your Gemfile to the following:
gem "database_cleaner", git: "https://github.com/DatabaseCleaner/database_cleaner", branch: "delay_safeguard"
Hi @botandrose, I tried it out. It works for me. Thanks mate!‚
Okay, great! I'll push this out as v2.0.1, presently. Thanks for the detailed reports, detective work, and testing, y'all!
Dependabot just upgraded
database_cleaner-active_record
to 2.0 and now all tests fail. I used to haveDatabaseCleaner.allow_remote_database_url = true
in my code.Open to see error message and trace log
```text Failure/Error: require File.expand_path('../config/environment', __dir__) DatabaseCleaner::Safeguard::Error::RemoteDatabaseUrl: ENV['DATABASE_URL'] is set to a remote URL. Please refer to https://github.com/DatabaseCleaner/database_cleaner#safeguards # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:45:in `run' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `block in run' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `each' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/safeguard.rb:104:in `run' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaner.rb:31:in `initialize' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:41:in `new' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:41:in `add_cleaner' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `block in []' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `fetch' # /usr/local/bundle/gems/database_cleaner-core-2.0.0/lib/database_cleaner/cleaners.rb:12:in `[]' # /usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record.rb:7:in `I also tried to set
DatabaseCleaner.url_allowlist = ['postgres://postgres@postgres']
, but this did not help.