Skip to content

Comments

Allow to define the default column serializer#47463

Merged
byroot merged 1 commit intorails:mainfrom
Shopify:configurable-default-column-serializer
Feb 22, 2023
Merged

Allow to define the default column serializer#47463
byroot merged 1 commit intorails:mainfrom
Shopify:configurable-default-column-serializer

Conversation

@casperisfine
Copy link
Contributor

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.

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.
@yahonda
Copy link
Member

yahonda commented Feb 23, 2023

There is are remaining DEPRECATION WARNING here.

https://buildkite.com/rails/rails/builds/94090#01867ae4-b402-4df0-a781-a02d1c55ff51/1139-1142

serialize :normal_blob, FrozenCoder.new(:normal_blob, Array)

klass = Class.new(ActiveRecord::Base) do
self.table_name = "tmp_posts"
serialize(:content, Hash)
end

klass = Class.new(ActiveRecord::Base) do
self.table_name = "tmp_posts"
serialize(:content, Hash)
end

@byroot
Copy link
Member

byroot commented Feb 23, 2023

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...

casperisfine pushed a commit to Shopify/rails that referenced this pull request Feb 23, 2023
Followup: rails#47463

I forgot I rebased on another PR that added two new serialization
tests.
@casperisfine casperisfine deleted the configurable-default-column-serializer branch February 23, 2023 08:14
byroot added a commit that referenced this pull request Feb 24, 2023
end

included do
class_attribute :default_column_serializer, instance_accessor: false, default: Coders::YAMLColumn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, they could also redefine ApplicationController.serialize to provide defaults. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 typo: evaludate -> evaluate

yahonda added a commit to yahonda/rails that referenced this pull request Feb 26, 2023
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
$
```
nikz added a commit to nikz/audited that referenced this pull request Feb 26, 2023
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)
gauravtiwari added a commit to gauravtiwari/noticed that referenced this pull request Feb 27, 2023
gauravtiwari added a commit to gauravtiwari/noticed that referenced this pull request Feb 27, 2023
matsales28 added a commit to matsales28/shoulda-matchers that referenced this pull request Oct 6, 2023
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
matsales28 added a commit to matsales28/shoulda-matchers that referenced this pull request Oct 6, 2023
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
matsales28 added a commit to matsales28/shoulda-matchers that referenced this pull request Oct 6, 2023
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
matsales28 added a commit to matsales28/shoulda-matchers that referenced this pull request Oct 6, 2023
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
matsales28 added a commit to matsales28/shoulda-matchers that referenced this pull request Oct 27, 2023
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
matsales28 added a commit to thoughtbot/shoulda-matchers that referenced this pull request Nov 17, 2023
* 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
kennyadsl added a commit to peterberkenbosch/solidus that referenced this pull request Dec 6, 2023
elia pushed a commit to peterberkenbosch/solidus that referenced this pull request Dec 20, 2023
elia pushed a commit to peterberkenbosch/solidus that referenced this pull request Dec 20, 2023
@KJTsanaktsidis
Copy link

Fun factoid - I could well be wrong, but it seems as if prior to this change, using store: ..., coder: JSON actually used real JSON as the coder, without the wrapping in ActiveRecord::Coders::JSON, whereas after this change, store behaves the same as serialize, and JSON gets automagically rewired to use ActiveRecord::Coders::JSON.

I think this is a good change (store and serialized should behave consistently!) but I didn't see it explicitly called out anywhere, so maybe it's also an accidentally good change.

noahfpf added a commit to FrontPorchForum/comfortable-mexican-sofa that referenced this pull request Mar 26, 2024
> 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.
Splines added a commit to MaMpf-HD/mampf that referenced this pull request Apr 22, 2024
Splines added a commit to MaMpf-HD/mampf that referenced this pull request Apr 26, 2024
* 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]>
Splines added a commit to MaMpf-HD/mampf that referenced this pull request May 30, 2024
* 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]>
sandbergja added a commit to pulibrary/bibdata that referenced this pull request Mar 21, 2025
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants