提交 f93b04af 编写于 作者: R Ryuta Kamizono

Deprecate marshalling load from legacy attributes format

Since #31827, marshalling attributes hash format is changed to improve
performance because materializing lazy attribute hash is too expensive.

In that time, we had kept an ability to load from legacy attributes
format, since that performance improvement is backported to 5-1-stable
and 5-0-stable.

Now all supported versions will dump attributes as new format, the
backward compatibity should no longer be needed.
上级 483330ee
* Deprecate marshalling load from legacy attributes format.
*Ryuta Kamizono*
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
topic.update!(status: :archived)
......
......@@ -78,6 +78,9 @@ def marshal_dump
def marshal_load(values)
if values.is_a?(Hash)
ActiveSupport::Deprecation.warn(<<~MSG.squish)
Marshalling load from legacy attributes format is deprecated and will be removed in Rails 6.2.
MSG
empty_hash = {}.freeze
initialize(empty_hash, empty_hash, empty_hash, empty_hash, values)
@materialized = true
......
......@@ -224,12 +224,13 @@ def assert_valid_value(*)
attributes.instance_variable_get(:@attributes).instance_eval do
class << self
def marshal_dump
materialize
materialize # legacy marshal format before Rails 5.1
end
end
end
attributes = Marshal.load(Marshal.dump(attributes))
data = Marshal.dump(attributes)
attributes = assert_deprecated { Marshal.load(data) }
assert_equal({ foo: "1" }, attributes.to_hash)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册