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 cant modify frozen Hash error due to rails changes #2482

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

vineelvineel
Copy link

Purpose

Latest rails has been updated to avoid repeated dup(https://github.com/rails/rails/pull/52826/files) of as_json options.

I have also had this issue last week.
Getting the following error when checking against a not match(rendering empty json array)

UsersController autocomplete with unmatched
  Failure/Error: format.json { render json: results }
  FrozenError:
    can't modify frozen Hash: {:prefixes=>["users", "application"], :template=>"autocomplete", :layout=>#<Proc:0x0000000131e8d960 /Users/admin/.rvm/gems/ruby-3.3.5@local/bundler/gems/rails-31818edb0352/actionview/lib/action_view/layouts.rb:393>, :serialization_context=>#<ActiveModelSerializers::SerializationContext:0x0000000131ecd088 @request_url="http://test.host/users/autocomplete", @query_parameters={"term"=>"unmatched"}, @url_helpers=#<Module:0x000000012cd22d00>, @default_url_options={:host=>"localhost:3000"}>, :namespace=>nil}
  # /Users/admin/.rvm/gems/ruby-3.3.5@local/gems/active_model_serializers-0.10.14/lib/active_model_serializers/adapter/attributes.rb:13:in `serializable_hash'

Changes

Using .dup so that code is not using the frozen options.

Caveats

N/A

Related GitHub issues

N/A

Additional helpful information

Related conversation in rails repository https://github.com/rails/rails/pull/52826/files#r1752237530

@chaadow
Copy link

chaadow commented Oct 9, 2024

thank you for the PR @vineelvineel

@mjankowski
Copy link

Just want to confirm that this branch resolves that frozen error issue for me in a rails 8.0.0.rc2 branch.

Curious if this will be looked at for merge?

@mrhaddad
Copy link

mrhaddad commented Nov 8, 2024

My test suite using this branch is green as well on a Rails 8.0.0 app.

@bf4 bf4 merged commit b21e78b into rails-api:0-10-stable Nov 16, 2024
12 checks passed
@bf4
Copy link
Member

bf4 commented Nov 16, 2024

Thanks, awesome! Want to add Rails 8 to CI?

@bf4 bf4 mentioned this pull request Nov 16, 2024
@devsheva
Copy link

how can we pull this fix? doesn't make sense to release a new patch version?

@mjankowski
Copy link

how can we pull this fix?

You can do something like....

gem 'active_model_serializers', github: 'rails-api/active_model_serializers', branch: '0-10-stable'

...which will pull from branch with fix.

doesn't make sense to release a new patch version?

Presumably with this PR and the linked rails-8-CI PR both merged, this might happen soon...?

@bf4
Copy link
Member

bf4 commented Dec 1, 2024

Presumably with this PR and the linked rails-8-CI PR both merged, this might happen soon...?

yup

@vineelvineel vineelvineel deleted the fix_cant_modify_frozen_hash branch December 1, 2024 20:49
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.

6 participants