Skip to content
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

Fix serialize method for Rails 7.1.2 compatibility #384

Closed
wants to merge 5 commits into from

Conversation

yhru
Copy link
Contributor

@yhru yhru commented Jan 4, 2024

Fix serialize method for Rails 7.1.2 compatibility

This commit resolves the ArgumentError: missing keyword: :coder issue encountered in Rails 7.1.2. It updates the serialize method in public_activity gem to include a default coder, ensuring compatibility with the newer Rails version. This change maintains backward compatibility with earlier versions of Rails.

@yhru yhru changed the title feat: add coder to serialize to work with Rails 7.1.2 Fix serialize method for Rails 7.1.2 compatibility Jan 4, 2024
@matthuhiggins
Copy link

@ur5us can you take a look?

@ur5us
Copy link
Collaborator

ur5us commented Jan 19, 2024

@yhru Initially, I thought that this won’t work with Rails ≤7.0 but it does due to how YAML is chosen as the default fallback prior versions of Rails, s. my comment #382 (comment). However, I was wrong and it totally works as expected so I’m happy to merge your PR. However, could you clean it up before I do so and simply remove the changes to the README as version 2.0.0 is not compatible with Rails 7.1, hence your PR. I suggest to simply remove the last 2 commits. I’ll then update the changelog and do a release.

@ur5us ur5us closed this in #385 Jan 19, 2024
ur5us added a commit that referenced this pull request Feb 14, 2024
Regression introduced in #5012e0d6. This change partially reverts the
change such that it works for Rails 6.1/7.0 and 7.1+.

In Rails 7.1+ the API for `.serialize` changed. At first using
`serialize :parameters, coder: YAML, type: Hash` seems to be backwards
compatible with Rails 6.1/7.0 when reading the documentation/code but
there’s a subtle difference: when the 2nd positional parameter
(denoting the target type) is not provided a default mechanism is used.
While the defaults will use `YAML` as the coder the serialization will
only occur if the column is not `NULL`. So, without an explicit type
parameter `nil`/`NULL` values are not converted to `Hash`. Thus, the
explicit type parameter acts as the fallback for the value itself.

Fixes #386 #384 #382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants