Skip to content

Dup as_json options if frozen for Rails 8 compatibility#625

Merged
ruckus merged 1 commit intoruckus:masterfrom
ignitionapp:as-json-frozen-hash-dup
Apr 14, 2025
Merged

Dup as_json options if frozen for Rails 8 compatibility#625
ruckus merged 1 commit intoruckus:masterfrom
ignitionapp:as-json-frozen-hash-dup

Conversation

@chrisrbnelson
Copy link
Contributor

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.

@ruckus ruckus merged commit f8fe839 into ruckus:master Apr 14, 2025
@ruckus
Copy link
Owner

ruckus commented Apr 14, 2025

Thank you!

ruckus pushed a commit that referenced this pull request Apr 14, 2025
Co-authored-by: Christopher Nelson <chris@chrisnelson.au>
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.

2 participants