aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actioncable/lib/action_cable/connection/authorization.rb2
-rw-r--r--activejob/CHANGELOG.md4
-rw-r--r--activejob/lib/active_job/arguments.rb5
-rw-r--r--activejob/lib/active_job/logging.rb12
-rw-r--r--activejob/test/cases/argument_serialization_test.rb5
-rw-r--r--activejob/test/cases/logging_test.rb10
-rw-r--r--activerecord/lib/active_record/connection_handling.rb22
-rw-r--r--activerecord/lib/active_record/locking/pessimistic.rb6
-rw-r--r--activerecord/lib/active_record/persistence.rb1
9 files changed, 44 insertions, 23 deletions
diff --git a/actioncable/lib/action_cable/connection/authorization.rb b/actioncable/lib/action_cable/connection/authorization.rb
index a22179d988..aef3386f71 100644
--- a/actioncable/lib/action_cable/connection/authorization.rb
+++ b/actioncable/lib/action_cable/connection/authorization.rb
@@ -5,7 +5,7 @@ module ActionCable
module Authorization
class UnauthorizedError < StandardError; end
- # Closes the \WebSocket connection if it is open and returns a 404 "File not Found" response.
+ # Closes the WebSocket connection if it is open and returns a 404 "File not Found" response.
def reject_unauthorized_connection
logger.error "An unauthorized connection attempt was rejected"
raise UnauthorizedError
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md
index 768e6bd250..8bbecd5a5a 100644
--- a/activejob/CHANGELOG.md
+++ b/activejob/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
+
+ *Gannon McGibbon*
+
* Include deserialized arguments in job instances returned from
`assert_enqueued_with` and `assert_performed_with`
diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb
index 8dcf588f35..31347194d2 100644
--- a/activejob/lib/active_job/arguments.rb
+++ b/activejob/lib/active_job/arguments.rb
@@ -147,7 +147,10 @@ module ActiveJob
end
def transform_symbol_keys(hash, symbol_keys)
- hash.transform_keys do |key|
+ # NOTE: HashWithIndifferentAccess#transform_keys always
+ # returns stringified keys with indifferent access
+ # so we call #to_h here to ensure keys are symbolized.
+ hash.to_h.transform_keys do |key|
if symbol_keys.include?(key)
key.to_sym
else
diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb
index 0abee4ed98..416be83c24 100644
--- a/activejob/lib/active_job/logging.rb
+++ b/activejob/lib/active_job/logging.rb
@@ -93,8 +93,12 @@ module ActiveJob
ex = event.payload[:error]
wait = event.payload[:wait]
- error do
- "Retrying #{job.class} in #{wait.inspect} seconds, due to a #{ex&.class.inspect}. The original exception was #{ex&.cause.inspect}."
+ info do
+ if ex
+ "Retrying #{job.class} in #{wait.to_i} seconds, due to a #{ex.class}."
+ else
+ "Retrying #{job.class} in #{wait.to_i} seconds."
+ end
end
end
@@ -103,7 +107,7 @@ module ActiveJob
ex = event.payload[:error]
error do
- "Stopped retrying #{job.class} due to a #{ex.class}, which reoccurred on #{job.executions} attempts. The original exception was #{ex.cause.inspect}."
+ "Stopped retrying #{job.class} due to a #{ex.class}, which reoccurred on #{job.executions} attempts."
end
end
@@ -112,7 +116,7 @@ module ActiveJob
ex = event.payload[:error]
error do
- "Discarded #{job.class} due to a #{ex.class}. The original exception was #{ex.cause.inspect}."
+ "Discarded #{job.class} due to a #{ex.class}."
end
end
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb
index f07529d743..8b2981926f 100644
--- a/activejob/test/cases/argument_serialization_test.rb
+++ b/activejob/test/cases/argument_serialization_test.rb
@@ -73,6 +73,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
string_key = { "a" => 1, "_aj_symbol_keys" => [] }
another_string_key = { "a" => 1 }
indifferent_access = { "a" => 1, "_aj_hash_with_indifferent_access" => true }
+ indifferent_access_symbol_key = symbol_key.with_indifferent_access
assert_equal(
{ a: 1 },
@@ -90,6 +91,10 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
{ "a" => 1 },
ActiveJob::Arguments.deserialize([indifferent_access]).first
)
+ assert_equal(
+ { a: 1 },
+ ActiveJob::Arguments.deserialize([indifferent_access_symbol_key]).first
+ )
end
test "should maintain hash with indifferent access" do
diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb
index b5bf40c83b..48ef39aaca 100644
--- a/activejob/test/cases/logging_test.rb
+++ b/activejob/test/cases/logging_test.rb
@@ -169,19 +169,19 @@ class LoggingTest < ActiveSupport::TestCase
def test_enqueue_retry_logging
perform_enqueued_jobs do
RetryJob.perform_later "DefaultsError", 2
- assert_match(/Retrying RetryJob in \d+ seconds, due to a DefaultsError\. The original exception was nil\./, @logger.messages)
+ assert_match(/Retrying RetryJob in 3 seconds, due to a DefaultsError\./, @logger.messages)
end
end
def test_enqueue_retry_logging_on_retry_job
perform_enqueued_jobs { RescueJob.perform_later "david" }
- assert_match(/Retrying RescueJob in nil seconds, due to a nil\. The original exception was nil\./, @logger.messages)
+ assert_match(/Retrying RescueJob in 0 seconds\./, @logger.messages)
end
def test_retry_stopped_logging
perform_enqueued_jobs do
RetryJob.perform_later "CustomCatchError", 6
- assert_match(/Stopped retrying RetryJob due to a CustomCatchError, which reoccurred on \d+ attempts\. The original exception was #<CustomCatchError: CustomCatchError>\./, @logger.messages)
+ assert_match(/Stopped retrying RetryJob due to a CustomCatchError, which reoccurred on \d+ attempts\./, @logger.messages)
end
end
@@ -190,7 +190,7 @@ class LoggingTest < ActiveSupport::TestCase
begin
RetryJob.perform_later "DefaultsError", 6
rescue DefaultsError
- assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\. The original exception was #<DefaultsError: DefaultsError>\./, @logger.messages)
+ assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages)
end
end
end
@@ -198,7 +198,7 @@ class LoggingTest < ActiveSupport::TestCase
def test_discard_logging
perform_enqueued_jobs do
RetryJob.perform_later "DiscardableError", 2
- assert_match(/Discarded RetryJob due to a DiscardableError\. The original exception was nil\./, @logger.messages)
+ assert_match(/Discarded RetryJob due to a DiscardableError\./, @logger.messages)
end
end
end
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index e3b59b8a22..777cb8a402 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -109,15 +109,19 @@ module ActiveRecord
if database && role
raise ArgumentError, "connected_to can only accept a database or role argument, but not both arguments."
elsif database
- database = { database => database } if database.is_a?(Symbol)
- database.each do |role, database_key|
- config_hash = resolve_config_for_connection(database_key)
- handler = lookup_connection_handler(role.to_sym)
-
- with_handler(role.to_sym) do
- handler.establish_connection(config_hash)
- return yield
- end
+ if database.is_a?(Hash)
+ role, database = database.first
+ role = role.to_sym
+ else
+ role = database.to_sym
+ end
+
+ config_hash = resolve_config_for_connection(database)
+ handler = lookup_connection_handler(role)
+
+ with_handler(role) do
+ handler.establish_connection(config_hash)
+ yield
end
elsif role
with_handler(role.to_sym, &blk)
diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb
index 5d1d15c94d..130ef8a330 100644
--- a/activerecord/lib/active_record/locking/pessimistic.rb
+++ b/activerecord/lib/active_record/locking/pessimistic.rb
@@ -14,9 +14,9 @@ module ActiveRecord
# of your own such as 'LOCK IN SHARE MODE' or 'FOR UPDATE NOWAIT'. Example:
#
# Account.transaction do
- # # select * from accounts where name = 'shugo' limit 1 for update
- # shugo = Account.where("name = 'shugo'").lock(true).first
- # yuko = Account.where("name = 'yuko'").lock(true).first
+ # # select * from accounts where name = 'shugo' limit 1 for update nowait
+ # shugo = Account.lock("FOR UPDATE NOWAIT").find_by(name: "shugo")
+ # yuko = Account.lock("FOR UPDATE NOWAIT").find_by(name: "yuko")
# shugo.balance -= 100
# shugo.save!
# yuko.balance += 100
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index f991a3076e..7bf8d568df 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -479,6 +479,7 @@ module ActiveRecord
verify_readonly_attribute(key.to_s)
end
+ id_in_database = self.id_in_database
attributes.each do |k, v|
write_attribute_without_type_cast(k, v)
end