-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the newer serialize
signature of Rails 7.1 if available
#776
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to raise the issue in Rails to see if it's the best place to put that config.
app/models/maintenance_tasks/run.rb
Outdated
@@ -46,8 +46,13 @@ class Run < ApplicationRecord | |||
|
|||
attr_readonly :task_name | |||
|
|||
serialize :backtrace | |||
serialize :arguments, JSON | |||
if respond_to?(:default_column_serializer) # Rails 7.1+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this is defined on ActiveRecord::Base
, I thought configurations were being moved to ActiveRecord
. rails/rails#42445
It's not a mattr_accessor
, but still confusing and if it's kept at the ActiveRecord::Base
level, we could also just set the value, as it wouldn't be global anyway.
self.default_column_serializer = YAML if respond_to?(:default_column_serializer=)
Also the accessor on ActiveRecord::Base is not documented, only as a configuration on config.active_record.default_column_serializer
, but these never explicitly say where they're being copied.
serialize :arguments, JSON | ||
if respond_to?(:default_column_serializer) # Rails 7.1+ | ||
serialize :backtrace, coder: YAML | ||
serialize :arguments, coder: JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if we're calling the method differently based on its parameters, we might as well use that as to make the distinction:
if method(:serialize).parameters.include?([:key, :coder])
or even just call it and rescue ArgumentError
.
Or maybe just a Active Record version check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with either. Let me know which you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version check is the safest and the easiest to grep for down the line when we want to remove that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version check sounds good to me as well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also curious about having this defined as a class attribute on on ActiveRecord::Base
vs an attr on ActiveRecord
's singleton 😄
Otherwise switching to the version check SGTM.
serialize :arguments, JSON | ||
if respond_to?(:default_column_serializer) # Rails 7.1+ | ||
serialize :backtrace, coder: YAML | ||
serialize :arguments, coder: JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version check sounds good to me as well 👍
3892d7e
to
27a94d9
Compare
app/models/maintenance_tasks/run.rb
Outdated
@@ -46,8 +46,13 @@ class Run < ApplicationRecord | |||
|
|||
attr_readonly :task_name | |||
|
|||
serialize :backtrace | |||
serialize :arguments, JSON | |||
if Rails.gem_version >= Gem::Version.new("7.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check against alpha to also include the current main.
if Rails.gem_version >= Gem::Version.new("7.1") | |
if Rails.gem_version >= Gem::Version.new("7.1.alpha") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh, I always forget that.
On 7.1 serialize properly split `coder` and `type` arguments instead of taking a single positional argument and try to figure out which is which. While we're at it, we can explictly define we're using YAML here instead of relying on the default that is now configurable.
27a94d9
to
e2fd841
Compare
serialize
signature if availableserialize
signature of Rails 7.1 if available
Ref: rails/rails#47463
On 7.1 serialize properly split
coder
andtype
arguments instead of taking a single positional argument and try to figure out which is which.While we're at it, we can explictly define we're using YAML here instead of relying on the default that is now configurable.