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

Dup as_json options if frozen for Rails 8 compatibility #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrisrbnelson
Copy link

Rails 8.0 introduced a change which freezes the options hash in ActiveSupport's .as_json method.

quickbooks-ruby overrides this method to add some ROXML exclusions, and this now breaks after updating to Rails 8.

# e.g. from calling `Quickbooks::Service::TaxCode.new(...).fetch_by_id(...).as_json`
FrozenError:
  can't modify frozen Hash: {except: ["roxml_references"]}
/cache/gems/ruby/3.4.0/gems/quickbooks-ruby-2.0.5/lib/quickbooks/model/base_model.rb:35:in 'Quickbooks::Model::BaseModel#as_json'
/cache/gems/ruby/3.4.0/gems/activesupport-8.0.1/lib/active_support/core_ext/object/json.rb:192:in 'block in Hash#as_json'
/cache/gems/ruby/3.4.0/gems/activesupport-8.0.1/lib/active_support/core_ext/object/json.rb:192:in 'Hash#each'
/cache/gems/ruby/3.4.0/gems/activesupport-8.0.1/lib/active_support/core_ext/object/json.rb:192:in 'Hash#as_json'
/cache/gems/ruby/3.4.0/gems/activesupport-8.0.1/lib/active_support/core_ext/object/json.rb:63:in 'Object#as_json'
/cache/gems/ruby/3.4.0/gems/quickbooks-ruby-2.0.5/lib/quickbooks/model/base_model.rb:36:in 'Quickbooks::Model::BaseModel#as_json'

The change also broke some other packages which do similar things.

This PR adds a check to dup the hash if it's frozen so it can be modified which avoids the issue.

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.

1 participant