提交 56f992fe 编写于 作者: C Cristian Bica

Fix for double ActiveJob::DeserializationErorr

上级 a4de217c
......@@ -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 @@ def serialize(arguments)
def deserialize(arguments)
arguments.map { |argument| deserialize_argument(argument) }
rescue => e
raise DeserializationError.new(e)
end
private
......@@ -40,7 +42,7 @@ def serialize_argument(argument)
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 @@ def serialize_argument(argument)
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册