Skip to content
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

3.0.0.rc try to access to the database when asset precompiling if it has config.model configuration #3469

Closed
ha4gu opened this issue Feb 13, 2022 · 1 comment · Fixed by #3470

Comments

@ha4gu
Copy link

ha4gu commented Feb 13, 2022

Describe the bug

If the Rails Admin's configuration file config/initializers/rails_admin.rb have config.model entry in it,
this rails application tries to access to the database when executing bin/rails assets:precomplie command.
(If no any config.model entries, it won't access to the database at all.)

So if there is no DB available, it fails to precompile. This is the output:

$ bin/rails assets:precompile
rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
/home/yuta/src/private/rails/rails-admin-eval/config/initializers/rails_admin.rb:43:in `block in <main>'
/home/yuta/src/private/rails/rails-admin-eval/config/environment.rb:5:in `<main>'

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
/home/yuta/src/private/rails/rails-admin-eval/config/initializers/rails_admin.rb:43:in `block in <main>'
/home/yuta/src/private/rails/rails-admin-eval/config/environment.rb:5:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)

Reproduction steps

  1. Create a new Rails application with PostgreSQL database and create a model.
  2. Install and setup Rails Admin following the installation process written on the README.
  3. bin/rails s to confirm that Rails Admin works nicely.
  4. Stop PostgreSQL server.
  5. Confirm bin/rails assets:precompile works.
  6. Add some config.model block to config/initializers/rails_admin.rb like following:
    RailsAdmin.config do |config|
      
      ...
      
      config.model "ModelYouHaveCreated" do
        visible true
      end
    end
    
  7. Confirm bin/rails assets:precompile fails.

Expected behavior

Asset precompile process completes without accessing to the DB, because Rails Admin 2.2.1 didn't access to the DB even in the same conditions.

(This behavior on 3.0.0.rc would cause a problem for my application's deployment process, which should be done on CI without DB.)

Additional context

pg 1.3.1
rails 6.1.4.6
rails_admin 3.0.0.beta2, 3.0.0.rc and current master (3d7f3b3), with config.asset_source = :webpacker in config/initializers/rails_admin.rb
webpacker 5.4.3

and with PostgreSQL 13 for DB
(* Sorry but I haven't checked if this behavior occurs with other databases like MySQL or not.)

@codealchemy
Copy link
Contributor

📝 Reproduced with a MySQL database on Rails 6.0

This looks to have been caused by e4ae669 - in particular, the RailsAdmin::Config.initialize! from the after_initialize hook (which sets up configured models)

When initializing abstract (ActiveRecord) models, #table_exists? is used and calls through the connection, which (in the case of a precompile step) can raise errors other than the ActiveRecord::NoDatabaseError that's currently handled.

I'll look into a fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants