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
Remove warning for serialize in rails 7.1+ #811
base: main
Are you sure you want to change the base?
Conversation
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) } | ||
options = options.merge(coder: class_name_or_coder, type: Object) | ||
else | ||
options = options.merge(coder: default_column_serializer, type: class_name_or_coder) | ||
end |
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.
This is what ActiveRecord
does to display the deprecation message & make the function still work
|
||
super(attr_name, **options) | ||
|
||
coder = build_column_serializer(attr_name, options[:coder], options[:type], options[:yaml]) |
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.
decided to use the build_column_serializer
private method on the class
Thanks for working on this @jwoodrow 👍🏼 . For the last commit fix tests we are seeing all tests fail in our app with the message: Psych::DisallowedClass:
Tried to dump unspecified class: ActiveSupport::HashWithIndifferentAccess Not sure why this is but will add further details if we discover the reason. Without that commit, everything looks to be working fine. |
That's odd especially because I haven't changed anything special and I haven't used any with_indifferent_access either 🤔 |
Investigating the error above, it seems that when the is being overwritten by the class My tests fail when an instance of This is undoubtedly not the solution but when I added the following the tests did pass: if options[:coder].blank?
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
options = options.merge(coder: class_name_or_coder, type: Object)
else
options = options.merge(coder: default_column_serializer, type: class_name_or_coder)
end
end
super(attr_name, **options) |
Kind of makes sense, if coder was provided by keyword chances are that there shouldn't be a need to determine a default value for coder or type 🤔 |
After trying to update one of our codebases that use globalize I finally encountered the same error with ActiveStorage::Blob. After adding the |
any Update on merging this? |
Hi Any update on this issue ? It's not clear what is required for checks to pass ? |
We switched over to Mobility following this recommendation and that worked out pretty well and was fairly seemless. |
Thanks, how did I not notice this suggestion?! There is also migration guide: https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize EDIT: One thing that this migration should mention is that
.. or something similar. |
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
``` Rendered shared/_social_media_meta_tags.html.erb DEPRECATION WARNING: Passing the class as positional argument is deprecated and will be removed in Rails 7.2. Please pass the class as a keyword argument: serialize :metadata, type: Object (called from require at <internal:/rbenv/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38) ```
That's one option, thanks for pointing it out. It'd be awesome if this PR could be finalized/merged such that those who want to upgrade to Rails 7.1 and only after that switch to mobility in a separate step could do so without all these deprecation warnings. Edit: At MaMpf, we switched from |
There was a warning that kept popping up because of how globalize was using
serialize
and the changes that are in effect in Rails 7.1 and will be permanently changed in Rails 7.2This PR uses the
ActiveRecord
conditions used to display the deprecation message and uses it to handle the detection betweencoder
/type
Also uses the
build_column_serializer
private method to build the coder assigned toglobalize_serialized_attributes