ActiveJob: fallback serializing String subclasses

https://github.com/rails/rails/pull/50090 broke serialization of String
subclasses that don't have serializers, like ActiveSupport::SafeBuffer.

Co-authored-by: John Hawthorn <john@hawthorn.email>
This commit is contained in:
Katherine Oelsner 2023-11-20 23:26:04 +00:00
parent 5d0ab554e3
commit e57e462a62
2 changed files with 16 additions and 1 deletions

View File

@ -76,7 +76,11 @@ module ActiveJob
if argument.class == String
argument
else
Serializers.serialize(argument)
begin
Serializers.serialize(argument)
rescue SerializationError
argument
end
end
when GlobalID::Identification
convert_to_global_id_hash(argument)

View File

@ -42,6 +42,9 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
end
end
class StringWithoutSerializer < String
end
setup do
@person = Person.find("5")
end
@ -156,6 +159,14 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
ActiveJob::Serializers._additional_serializers = original_serializers
end
test "serialize a String subclass object without a serializer" do
string_without_serializer = StringWithoutSerializer.new("foo")
serialized = ActiveJob::Arguments.serialize([string_without_serializer])
deserialized = ActiveJob::Arguments.deserialize(JSON.load(JSON.dump(serialized))).first
assert_instance_of String, deserialized
assert_equal string_without_serializer, deserialized
end
test "serialize a hash" do
symbol_key = { a: 1 }
string_key = { "a" => 1 }