Skip to content

Commit

Permalink
Add caveat about normalizes / Marshal interaction [ci-skip]
Browse files Browse the repository at this point in the history
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 #49871.
  • Loading branch information
jonathanhefner committed Oct 31, 2023
1 parent 2947e5b commit 7faba03
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions activerecord/lib/active_record/normalization.rb
Expand Up @@ -49,6 +49,14 @@ module ClassMethods
# By default, the normalization will not be applied to +nil+ values. This
# behavior can be changed with the +:apply_to_nil+ option.
#
# Be aware that if your app was created before Rails 7.1, and your app
# marshals instances of the targeted model (for example, when caching),
# then you should set ActiveRecord.marshalling_format_version to +7.1+ or
# higher via either <tt>config.load_defaults 7.1</tt> or
# <tt>config.active_record.marshalling_format_version = 7.1</tt>.
# Otherwise, +Marshal+ may attempt to serialize the normalization +Proc+
# and raise +TypeError+.
#
# ==== Options
#
# * +:with+ - Any callable object that accepts the attribute's value as
Expand Down

0 comments on commit 7faba03

Please sign in to comment.