Skip to content

Resolve Rails 6.1 deprecation warning re: connection_config#365

Merged
cschneid merged 1 commit intoscoutapp:masterfrom
jasonrudolph:resolve-rails-6-1-warning-re-connection-config
May 22, 2021
Merged

Resolve Rails 6.1 deprecation warning re: connection_config#365
cschneid merged 1 commit intoscoutapp:masterfrom
jasonrudolph:resolve-rails-6-1-warning-re-connection-config

Conversation

@jasonrudolph
Copy link
Contributor

Prior to this change, the first interaction with the database would emit the following deprecation warning with Rails 6.1:

DEPRECATION WARNING: connection_config is deprecated and will be removed from Rails 6.2 (Use connection_db_config instead)

The deprecation was introduced in rails/rails#38005 and includes the following release notes:

The connection_config method has been deprecated, please use connection_db_config instead which will return a DatabaseConfigurations::DatabaseConfig instead of a Hash.

Proposed resolution

With the changes in the pull request, Scout first attempts to use connection_db_config. If unsuccessful, Scout falls back to the previous behavior of using connection_config.

How to reproduce the deprecation warning

  1. Verify you're using Rails 6.1:

    $ rails -v
    Rails 6.1.0
    
  2. Set up a new Rails app with scout_apm:

    $ rails new sample --database=postgresql
    $ cd sample/
    $ rails db:create
    $ rails generate model User name:string
    $ rails db:migrate
    $ bundle add scout_apm 
    
  3. Load Scout and interact with the database:

    $ SCOUT_DEV_TRACE=true rails console
    
    2.7.2-p137> User.count
    DEPRECATION WARNING: connection_config is deprecated and will be removed from Rails 6.2 (Use connection_db_config instead) (called from irb_binding at (irb):1)
      (0.4ms)  SELECT COUNT(*) FROM "users"
    => 0
    

Prior to this change, the first interaction with the database would emit
the following deprecation warning with Rails 6.1:

> DEPRECATION WARNING: connection_config is deprecated and will be
removed from Rails 6.2 (Use connection_db_config instead)

For more info, see rails/rails#38005 which
introduced the deprecation.
@cschneid
Copy link
Contributor

Thank you for this PR. Sorry it's taking a bit to take a look at, lots of time off over holidays 😄 . I'll get this tested & merged as soon as I can.

end

if adapter.nil?
adapter = ActiveRecord::Base.configurations[env]["adapter"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another depreciation, using [] for the configurations method. If it is your intention please consider replacing it with configs_for

adapter = ActiveRecord::Base.configurations.configs_for(env)["adapter"]

rails/rails#33637

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be backwards compatible a long ways, so we can't just change it to that blindly. Do we hit this branch on 6.1+ after checking the line above with connection_db_config?

I'll have to check it out

@ddarren
Copy link

ddarren commented Mar 4, 2021

Thank you for this PR. Sorry it's taking a bit to take a look at, lots of time off over holidays 😄 . I'll get this tested & merged as soon as I can.

@cschneid Any news on getting this merged or when we can expect it? Still getting this on 4.0.4. Thanks!

@rubendinho
Copy link

Hi there - are there any updates on this?

@benhart
Copy link

benhart commented Apr 28, 2021

Hi - any idea when this will be merged and released? Or is there another way for us to avoid the deprecation warnings?

@cschneid cschneid merged commit 0fda5f1 into scoutapp:master May 22, 2021
cschneid added a commit that referenced this pull request May 22, 2021
@jasonrudolph
Copy link
Contributor Author

Thanks for getting this merged in, @cschneid. 🙇

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants