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

Support Rails 8 #2483

Merged
merged 1 commit into from
Nov 28, 2024
Merged

Support Rails 8 #2483

merged 1 commit into from
Nov 28, 2024

Conversation

pulkit110
Copy link

@pulkit110 pulkit110 commented Nov 11, 2024

Purpose

Support Rails 8

Changes

There are two main changes:

  1. To allow modification of render options (to initialize defaults) from adapters, dup it if it's frozen.
  2. ActiveSupport::Deprecation.silence is replaced by Rails.deprecator.silence

This PR also adds Rails 7.2 and 8.0 to the test matrix.

Caveats

No caveats

Related GitHub issues

No related issues

Additional helpful information

This is my first contribution, so please let me know if something is missing and I'll try to answer it.

@@ -74,7 +74,8 @@ def fragment_cache(cached_hash, non_cached_hash)
# see https://github.com/rails-api/active_model_serializers/pull/965
# When <tt>options</tt> is +nil+, sets it to +{}+
def serialization_options(options)
options ||= {} # rubocop:disable Lint/UselessAssignment
options ||= {}
options.frozen? ? options.dup : options

Choose a reason for hiding this comment

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

Curious if the cost of checking for freezing here is worth it vs. always duplicating.

Copy link
Author

Choose a reason for hiding this comment

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

I ran a synthetic benchmark, and both options show almost identical performance:

                             user     system      total        real
Always dup:              0.458805   0.015979   0.474784 (  0.475676)
Cond. dup (frozen):      0.460826   0.014778   0.475604 (  0.476971)
Cond. dup (not frozen):  0.459270   0.010303   0.469573 (  0.471081)

For reference, here is the script I used.

Copy link
Member

@bf4 bf4 left a comment

Choose a reason for hiding this comment

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

I'd love to isolate this to the minimum change to get CI running on Rails 8 with the minimum runtime (vs. load time) differences. I've merged #2482

You up for focusing this PR on CI and getting it passing? It looks good

@pulkit110
Copy link
Author

@bf4 Thanks for your reply. The CI is already passing: https://github.com/pulkit110/active_model_serializers/actions/runs/11772425914 and there are no runtime differences:
Screenshot 2024-11-16 at 02 45 26

Please let me know if you need any changes from my side to get this ready for merge.

@pulkit110
Copy link
Author

FYI I have rebased my branch on 0-10-stable and the CI is passing: https://github.com/pulkit110/active_model_serializers/actions/runs/11866564182

@mjankowski
Copy link

Looks like this needs workflow approval after rebase?

@pulkit110
Copy link
Author

I noticed that the workflow was failing, so I pushed a fix in f33e76c

The workflow requires approval again.

test/support/isolated_unit.rb Outdated Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
@wasifhossain
Copy link
Member

Looks good to me. Let's merge this.
Thank you @pulkit110 !!

@wasifhossain wasifhossain merged commit eef9fd2 into rails-api:0-10-stable Nov 28, 2024
15 checks passed
@bf4
Copy link
Member

bf4 commented Dec 1, 2024

Thanks for your work. Released 0.10.15

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.

5 participants