diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-05-01 13:33:50 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-05-01 13:33:50 -0400 |
commit | 5b9cd1a57992a47f323cefc9dd785a45468759b0 (patch) | |
tree | 662584a67ac1b6dd84abc54f3ba0dc10ac078f5e /activejob/lib | |
parent | ac2bc00482c1cf47a57477edb6ab1426a3ba593c (diff) | |
download | rails-5b9cd1a57992a47f323cefc9dd785a45468759b0.tar.gz rails-5b9cd1a57992a47f323cefc9dd785a45468759b0.tar.bz2 rails-5b9cd1a57992a47f323cefc9dd785a45468759b0.zip |
Make sure that when serialing an just deserialized job arguments are there
When a job was just deserialized `arguments` is `nil` and the serialized
arguments are in the `@serialized_arguments` variable. If we try to
serialize this job again the arguments are going to be `nil` instead of
what was serialized.
The test we had was not checking this case because it was deserializing
the job in the same object that had the arguments.
To fix this, when the `@serialized_arguments` are present we return it
instead of the result of the `arguments` serialized.
Diffstat (limited to 'activejob/lib')
-rw-r--r-- | activejob/lib/active_job/core.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index da841ae45b..61d402cfca 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -88,7 +88,7 @@ module ActiveJob "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority, - "arguments" => serialize_arguments(arguments), + "arguments" => serialize_arguments_if_needed(arguments), "executions" => executions, "locale" => I18n.locale.to_s, "timezone" => Time.zone.try(:name) @@ -133,19 +133,31 @@ module ActiveJob end private + def serialize_arguments_if_needed(arguments) + if arguments_serialized? + @serialized_arguments + else + serialize_arguments(arguments) + end + end + def deserialize_arguments_if_needed - if defined?(@serialized_arguments) && @serialized_arguments.present? + if arguments_serialized? @arguments = deserialize_arguments(@serialized_arguments) @serialized_arguments = nil end end - def serialize_arguments(serialized_args) - Arguments.serialize(serialized_args) + def serialize_arguments(arguments) + Arguments.serialize(arguments) end def deserialize_arguments(serialized_args) Arguments.deserialize(serialized_args) end + + def arguments_serialized? + defined?(@serialized_arguments) && @serialized_arguments + end end end |