Allow to define the default column serializer#47463
Conversation
YAML has quite a bit of footguns, as such it's desirable to be able to substitute it for something else or even simply to force users to define a serializer explictly for every serialized columns.
|
There is are remaining rails/activerecord/test/cases/serialized_attribute_test.rb Lines 417 to 420 in ee6a7ba rails/activerecord/test/cases/serialized_attribute_test.rb Lines 440 to 443 in ee6a7ba |
|
Thank you @yahonda. I'm and idiot I merged the PR that added these tests and I rebased on top of it, I forgot to update them... |
Followup: rails#47463 I forgot I rebased on another PR that added two new serialization tests.
| end | ||
|
|
||
| included do | ||
| class_attribute :default_column_serializer, instance_accessor: false, default: Coders::YAMLColumn |
There was a problem hiding this comment.
This does not create a global default but instead is configurable for each subclass of ActiveRecord::Base. The ability to configure each serialize is enough, plus a global default for compatibility should be enough.
There was a problem hiding this comment.
I can make it a global, but I thought having it inheritable made sense for say engines so that they can have their base abstract model, and define the serializer they use across the engine centrally.
There was a problem hiding this comment.
Hum, they could also redefine ApplicationController.serialize to provide defaults. 🤔
There was a problem hiding this comment.
And break if we change the signature. I prefer a class attribute.
| # ==== Choosing a serializer | ||
| # | ||
| # While any serialization format can be used, it is recommended to carefully | ||
| # evaludate the properties of a serializer before using it, as migrating to |
There was a problem hiding this comment.
👀 typo: evaludate -> evaluate
Follow up rails#47463 ```ruby $ ARCONN=mysql2 bin/test test/cases/serialized_attribute_test.rb -n test_is_not_changed_when_stored_in_mysql_blob_frozen_payload Using mysql2 DEPRECATION WARNING: Passing the coder as positional argument is deprecated and will be remove in Rails 7.2. Please pass the coder as a keyword argument: serialize :normal_blob, coder: #<SerializedAttributeTest::FrozenBinaryField::FrozenCoder:0x00007f59ebdcaf40> (called from <class:FrozenBinaryField> at /home/yahonda/src/github.com/rails/rails/activerecord/test/cases/serialized_attribute_test.rb:380) /home/yahonda/src/github.com/rails/rails/activerecord/test/cases/serialized_attribute_test.rb:380:in `<class:FrozenBinaryField>' /home/yahonda/src/github.com/rails/rails/activerecord/test/cases/serialized_attribute_test.rb:374:in `<class:SerializedAttributeTest>' /home/yahonda/src/github.com/rails/rails/activerecord/test/cases/serialized_attribute_test.rb:9:in `<top (required)>' /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `require' /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `block in load_tests' /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `each' /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:50:in `load_tests' /home/yahonda/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:42:in `run' /home/yahonda/src/github.com/rails/rails/activerecord/test/support/tools.rb:37:in `<top (required)>' bin/test:11:in `require_relative' bin/test:11:in `<main>' Run options: -n test_is_not_changed_when_stored_in_mysql_blob_frozen_payload --seed 33922 .. Finished in 0.067710s, 29.5376 runs/s, 29.5376 assertions/s. 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips $ ```
As a result of [Rails PR#47463](rails/rails#47463), serialization is now type-checked, and so the approach of dynamically deciding on `#load` and `#dump` no longer works. This commit adds a configuration setting to choose json encoding by default (replaces the existing approach where the coder was dynamaically determined by database column type)
This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to
This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to
This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to
This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to
This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to
* Add Rails 7.1 to appraisals * fix: Adjust validate options when managing columns and tables in migration This commit adjusts the way we manage columns and tables in migrations to account for the changes in Rails 7.1.0, it was introduced in this Rails version a validation around the options passed to tables and columns in migrations, so we need to adjust our code to skip this validation. This PR introduced this new validation on the migrations: rails/rails#46178 * Refine `ActiveRecord::SerializeMatcher` for Rails 7.1 compatibility This commit refines the `ActiveRecord::SerializeMatcher` to accommodate changes in the public API introduced in Rails 7.1. The `serialize` method's API has been updated, necessitating adjustments to our matcher specs to align with the new API. While this PR addresses the immediate need for compatibility, there is potential for further enhancements and refinements in the matcher's implementation to bring it in line with the revised public API. However, such improvements will be explored in a future PR. For reference, the changes in the public API can be found in the following PR: rails/rails#47463 This commit adjusts the `ActiveRecord::SerializeMatcher` the public API for the `serialize` method has changed on Rails 7.1, so we had to * feat: Upadte workflow matrix * fix: Adjust comparison between hash and `ActionController::Parameters` The behavior of the comparison between hash and a `ActionController::Parameters` was changed and now will be deprecated. Check this Rails PR for more context rails/rails#44826. * fix: Adjust usage of `has_secure_token` without a token attr The behaviour of this method was changed in Rails 7.1, and now it'll search for a `token` attr in the initialization of the record instead of the creation. To stay with the same behaviour as before it's necessary to pass a new argument `on: : create` to the method. * fix: Adjust specs for primary_key check * fix: Test updating error_highlight gem * fix: Add default Rails tables to acceptance spec This commit fixes the problem of not finding the tables when running the specs in eager load mode, this was introduced by Rails 7.1. Load the model schema when running test in eager load context rails/rails#49470
This is mandatory for Rails 7.1. Ref: - https://api.rubyonrails.org/v7.1.0/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html - rails/rails#47463 Co-Authored-By: Alberto Vena <[email protected]>
This is mandatory for Rails 7.1. Ref: - https://api.rubyonrails.org/v7.1.0/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html - rails/rails#47463 Co-Authored-By: Alberto Vena <[email protected]>
|
Fun factoid - I could well be wrong, but it seems as if prior to this change, using I think this is a good change ( |
> ArgumentError: missing keyword: :coder If no default coder is configured, a coder must be provided to `serialize`. See rails/rails#47463 for background on this change.
This is a followup to rails/rails#47463
* Upgrade Rails to v7.1 and run `bundle update` See the upgrade guide here: https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html * Use older version of `html-parser` for `thredded` See thredded/thredded#979 * Use new `config.autoload_lib` in Rails 7.1 See https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#config-autoload-lib-and-config-autoload-lib-once Eager loading is on by default for production. * Remove unused app environment variables usage The file `config/app_environment_variables.rb` does not exist in our codebase anymore. * Run `bin/rails app:update` to update configurations * Add new framework defaults for Rails 7.1 file * Update `listen` gem version This was done because `bin/rails app:update` failed with: ** Execute app:update:active_storage rails active_storage:update bin/rails aborted! Gem::LoadError: can't activate listen (~> 3.5), already activated listen-3.0.8. Make sure all dependencies are added to Gemfile. * Add TODO note for upcoming serialize change * Reduce new framework defaults list * Add migrations introduced by rails update task * Remove unneeded ActiveStorage migrations * Remove defaults for sha-256 as we are unaffected * Use new Rails 7.1 defaults * Fix TODO rubocop warning * Update bundler version to 2.5.9 You can do so locally via `bundle update --bundler` * Remove unnecessary entries in `Gemfile.lock` Performed automatically via `bundle install`. * Address `Passing the coder as positional arg` deprecation This is a followup to rails/rails#47463 * add yaml coder explicitly for serializing arrays * Migrate from globalize to mobility due to serialization warnings * Update gem lockfile to include `mobility` `bundle install` also removed globalize automatically for us. * Add `I18nLocaleAccessors` as replacement for `globalize_attribute_names` * Remove obsolete comment regarding `globalize` * Fix Rails `secrets` deprecation warning (Devise) This is due to heartcombo/devise#5644. * Use `install_folder` in cypress on rails `cypress_folder` is deprecated as config option --------- Co-authored-by: fosterfarrell9 <[email protected]>
* Upgrade Rails to v7.1 and run `bundle update` See the upgrade guide here: https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html * Use older version of `html-parser` for `thredded` See thredded/thredded#979 * Use new `config.autoload_lib` in Rails 7.1 See https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#config-autoload-lib-and-config-autoload-lib-once Eager loading is on by default for production. * Remove unused app environment variables usage The file `config/app_environment_variables.rb` does not exist in our codebase anymore. * Run `bin/rails app:update` to update configurations * Add new framework defaults for Rails 7.1 file * Update `listen` gem version This was done because `bin/rails app:update` failed with: ** Execute app:update:active_storage rails active_storage:update bin/rails aborted! Gem::LoadError: can't activate listen (~> 3.5), already activated listen-3.0.8. Make sure all dependencies are added to Gemfile. * Add TODO note for upcoming serialize change * Reduce new framework defaults list * Add migrations introduced by rails update task * Remove unneeded ActiveStorage migrations * Remove defaults for sha-256 as we are unaffected * Use new Rails 7.1 defaults * Fix TODO rubocop warning * Update bundler version to 2.5.9 You can do so locally via `bundle update --bundler` * Remove unnecessary entries in `Gemfile.lock` Performed automatically via `bundle install`. * Address `Passing the coder as positional arg` deprecation This is a followup to rails/rails#47463 * add yaml coder explicitly for serializing arrays * Migrate from globalize to mobility due to serialization warnings * Update gem lockfile to include `mobility` `bundle install` also removed globalize automatically for us. * Add `I18nLocaleAccessors` as replacement for `globalize_attribute_names` * Remove obsolete comment regarding `globalize` * Fix Rails `secrets` deprecation warning (Devise) This is due to heartcombo/devise#5644. * Use `install_folder` in cypress on rails `cypress_folder` is deprecated as config option * Init dummy Bootstrap nav pills * Group accordion items into nav pane * Style pillars & improve accessibility * Remove accordion wrappers & design lecture content pane * Center lectures header & improve vertical alignment * Add margin to bottom of lecture pane * Internationalize lectures navbar headers * Decaffeinate `lectures.coffee` via local CLI of decaffeinate see https://decaffeinate-project.org/ * Format `lectures.js` according to ESLint * Remove unnecessary use of Array.from * Use shorter variations of null checks * Remove unnecessary Coffeescript comment * Fix ESLint errors * Make better use of JS function syntax * Configure url hashes for bootstrap tabs Might also be known as "deep linking". * Simplify url hash update logic * Remove unused variable `s` * Use focus listener (not click listener) for accessibility * Implement many small UI improvements in lectures * Re-initialize masonry grid system for lecture content * Remove unnecessary spacing * Add confirmation dialog to delete forum * Add scrollbar to announcements list if too long * Redirect to correct page after creating a new announcement * Redirect to correct page after "Forum" actions * Redirect to correct page after "Comments" actions * Increase bottom margin of lecture pane * Check if errors are present to avoid nil error * Fix valid_annotations_status include check * Only load lectures_admin js related code when needed We also perform an early return if we no erdbeere examples are searched for, i.e. when the element is not yet visible on the page. * Use icons for save/cancel in assignments table * Fix structures cancel button (erdbeere) * Improve positioning of "structures" text * Get rid of unused debug message * Fix import of media for lectures not working * Remove TODO note * Delete unused tags/modal partial rendering * Stay on subpage upon save action * Fix broken browser navigation * Fix weird masonry grid system bug * Wait until tab content is shown before setting up grid system --------- Co-authored-by: fosterfarrell9 <[email protected]>
* enum has a slightly different API (see rails/rails#50987) * you now should specify a coder for serialized columns (see rails/rails#47463). Use YAML for backwards compatibility. * we weren't actually using one of the serialized columns, and it doesn't even exist in the database. Remove it from the model.
YAML has quite a bit of footguns, as such it's desirable to be able to substitute it for something else or even simply to force users to define a serializer explictly for every serialized columns.
This is a scaled back version of #47422. This make the default configurable, and we can have a discussion on whether or not we wish to change the default (and what it should be) in a followup.