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

Fix: PG.connect keyword arguments deprecation warning on ruby 2.7 #45090

Merged
merged 2 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Fix PG.connect keyword arguments deprecation warning on ruby 2.7

Fixes #44307.

*Nikita Vasilevsky*

## Rails 6.1.6 (May 09, 2022) ##

* No changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PostgreSQLAdapter < AbstractAdapter

class << self
def new_client(conn_params)
PG.connect(conn_params)
PG.connect(**conn_params)
rescue ::PG::Error => error
if conn_params && conn_params[:dbname] && error.message.include?(conn_params[:dbname])
raise ActiveRecord::NoDatabaseError
Expand Down Expand Up @@ -247,7 +247,7 @@ def connection_active?
def initialize(connection, logger, connection_parameters, config)
super(connection, logger, config)

@connection_parameters = connection_parameters
@connection_parameters = connection_parameters || {}

# @local_tz is initialized as nil to avoid warnings when connect tries to use it
@local_tz = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def exec_params(*)
end

def reset
raise PG::ConnectionBad
raise PG::ConnectionBad, "I'll be rescued by the reconnect method"
end

def close
Expand All @@ -53,8 +53,13 @@ def close
{ host: File::NULL }
)

assert_raises ActiveRecord::ConnectionNotEstablished do
@conn.reconnect!
connect_raises_error = proc { |_conn_params| raise(PG::ConnectionBad, "actual bad connection error") }
PG.stub(:connect, connect_raises_error) do
error = assert_raises ActiveRecord::ConnectionNotEstablished do
@conn.reconnect!
end

assert_equal("actual bad connection error", error.message)
end
end

Expand Down