mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix for double ActiveJob::DeserializationErorr
This commit is contained in:
parent
a4de217ce5
commit
56f992fe15
2 changed files with 10 additions and 5 deletions
|
@ -5,7 +5,7 @@ module ActiveJob
|
|||
class DeserializationError < StandardError
|
||||
attr_reader :original_exception
|
||||
|
||||
def initialize(e)
|
||||
def initialize(e) #:nodoc:
|
||||
super ("Error while trying to deserialize arguments: #{e.message}")
|
||||
@original_exception = e
|
||||
set_backtrace e.backtrace
|
||||
|
@ -30,6 +30,8 @@ module ActiveJob
|
|||
|
||||
def deserialize(arguments)
|
||||
arguments.map { |argument| deserialize_argument(argument) }
|
||||
rescue => e
|
||||
raise DeserializationError.new(e)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -40,7 +42,7 @@ module ActiveJob
|
|||
when *TYPE_WHITELIST
|
||||
argument
|
||||
when Array
|
||||
serialize(argument)
|
||||
argument.map { |arg| serialize_argument(arg) }
|
||||
when Hash
|
||||
Hash[ argument.map { |key, value| [ serialize_hash_key(key), serialize_argument(value) ] } ]
|
||||
else
|
||||
|
@ -51,14 +53,12 @@ module ActiveJob
|
|||
def deserialize_argument(argument)
|
||||
case argument
|
||||
when Array
|
||||
deserialize(argument)
|
||||
argument.map { |arg| deserialize_argument(arg) }
|
||||
when Hash
|
||||
Hash[ argument.map { |key, value| [ key, deserialize_argument(value) ] } ].with_indifferent_access
|
||||
else
|
||||
GlobalID::Locator.locate(argument) || argument
|
||||
end
|
||||
rescue => e
|
||||
raise DeserializationError.new(e)
|
||||
end
|
||||
|
||||
def serialize_hash_key(key)
|
||||
|
|
|
@ -28,4 +28,9 @@ class RescueTest < ActiveSupport::TestCase
|
|||
assert_includes JobBuffer.values, 'DeserializationError original exception was Person::RecordNotFound'
|
||||
assert_not_includes JobBuffer.values, 'performed beautifully'
|
||||
end
|
||||
|
||||
test "should not wrap DeserializationError in DeserializationError" do
|
||||
RescueJob.enqueue [Person.new(404)]
|
||||
assert_includes JobBuffer.values, 'DeserializationError original exception was Person::RecordNotFound'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue