Skip to content

Commit 7faba03

Browse files
Add caveat about normalizes / Marshal interaction [ci-skip]
When `ActiveRecord.marshalling_format_version` is set to `6.1`, `Marshal` will try to serialize attribute types along with the model, causing a `TypeError` if the model uses `ActiveRecord::Base.normalizes` with a normalization `Proc`. This commit adds a caveat to the `normalizes` API documentation to warn users that they should set `marshalling_format_version` to `7.1` if they are using `normalizes` and marshalling the targeted model. Fixes rails#49871.
1 parent 2947e5b commit 7faba03

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

activerecord/lib/active_record/normalization.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ module ClassMethods
4949
# By default, the normalization will not be applied to +nil+ values. This
5050
# behavior can be changed with the +:apply_to_nil+ option.
5151
#
52+
# Be aware that if your app was created before Rails 7.1, and your app
53+
# marshals instances of the targeted model (for example, when caching),
54+
# then you should set ActiveRecord.marshalling_format_version to +7.1+ or
55+
# higher via either <tt>config.load_defaults 7.1</tt> or
56+
# <tt>config.active_record.marshalling_format_version = 7.1</tt>.
57+
# Otherwise, +Marshal+ may attempt to serialize the normalization +Proc+
58+
# and raise +TypeError+.
59+
#
5260
# ==== Options
5361
#
5462
# * +:with+ - Any callable object that accepts the attribute's value as

0 commit comments

Comments
 (0)