audited
audited copied to clipboard
Reflect Rails' serializer changes
As a result of Rails PR#47463, serialization is now type-checked, and so the approach of dynamically deciding when calling #load
and #dump
no longer works.
This means that you'll get the following errors/deprecation warnings when using Edge Rails with Audited:
DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be remove in Rails 7.2.
Please pass the class as a keyword argument:
serialize :audited_changes, type: Audited::YAMLIfTextColumnType
(called from <class:Audit> at /Users/nik/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/audited-5.3.2/lib/audited/audit.rb:52)
And:
ActiveRecord::SerializationTypeMismatch: can't serialize `audited_changes`: was supposed to be a Audited::YAMLIfTextColumnType, but was a Hash. -- { ... }
(The first is just a syntax thing to be fair)
I don't know the best way to fix it to be honest - determining the column type would require connecting to the database on load, so that's sub-optimal. It might be possible to implement a Coder
class that dynamically switches and passes the type checking?
This is the commit I'm using, which adds a configuration setting to choose json encoding by default (replaces the existing approach). This seems like something worth considering as it seems Rails has moved away from YAML for good reasons too.
I've sent the PR in case it's useful, but of course it's a breaking change and I think there might be a better approach - figured I'd start the discussion anyway 😄
Thank you!