Raise error when serializing an anonymous class.
The ModuleSerializer does not support serializing anonymous classes because when we try to deserialize the anonymous class, it wouldn't know which class to use (since class name is nil). For this reason, ModuleSerialzier now raises an error if the class name is nil. Previously, ModuleSerializer would raise an `undefined method `constantize' for nil:NilClass` error during deserialization. It's not clear why the deserialization failed from the error. In this commit, we raise an explicit error when trying to serialize an anonymous class indicating this behaviour is not supported.
This commit is contained in:
parent
f2be2b013c
commit
0f259e702d
|
@ -1,3 +1,9 @@
|
|||
* Raise an `SerializationError` in `Serializer::ModuleSerializer`
|
||||
if the module name is not present.
|
||||
|
||||
*Veerpal Brar*
|
||||
|
||||
|
||||
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
||||
|
||||
* No changes.
|
||||
|
|
|
@ -4,6 +4,7 @@ module ActiveJob
|
|||
module Serializers
|
||||
class ModuleSerializer < ObjectSerializer # :nodoc:
|
||||
def serialize(constant)
|
||||
raise SerializationError, "Serializing an anonymous class is not supported" unless constant.name
|
||||
super("value" => constant.name)
|
||||
end
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
[ Object.new, Person.find("5").to_gid ].each do |arg|
|
||||
[ Object.new, Person.find("5").to_gid, Class.new ].each do |arg|
|
||||
test "does not serialize #{arg.class}" do
|
||||
assert_raises ActiveJob::SerializationError do
|
||||
ActiveJob::Arguments.serialize [ arg ]
|
||||
|
|
Loading…
Reference in New Issue