From 7faba032d01a8df147a0c90f09fdcd65e1d8bbb4 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Tue, 31 Oct 2023 16:16:37 -0500 Subject: [PATCH] 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 #49871. --- activerecord/lib/active_record/normalization.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/activerecord/lib/active_record/normalization.rb b/activerecord/lib/active_record/normalization.rb index 5f274321a03a..7c3ade6d2f6b 100644 --- a/activerecord/lib/active_record/normalization.rb +++ b/activerecord/lib/active_record/normalization.rb @@ -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 config.load_defaults 7.1 or + # config.active_record.marshalling_format_version = 7.1. + # Otherwise, +Marshal+ may attempt to serialize the normalization +Proc+ + # and raise +TypeError+. + # # ==== Options # # * +:with+ - Any callable object that accepts the attribute's value as