Skip to content

fix: has_json accessors after requiring active_model - #57310

Merged
rafaelfranca merged 1 commit into
rails:mainfrom
tellodaniel:fix-has-json-active-model-standalone
May 7, 2026
Merged

rafaelfranca merged 1 commit into
rails:mainfrom
tellodaniel:fix-has-json-active-model-standalone

Conversation

@tellodaniel

@tellodaniel tellodaniel commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation / Background

ActiveModel::SchematizedJson calls String#remove, which is defined by active_support/core_ext/string/filters.

That dependency is currently implicit. When ActiveModel::SchematizedJson is loaded without another file having already loaded that string extension, calling a has_json accessor can raise a NoMethodError.

Detail

This Pull Request makes the dependency explicit by requiring active_support/core_ext/string/filters from active_model/schematized_json.

Additional information

I verified the fix with a standalone Active Model script and the Active Model test suite.

No CHANGELOG entry was added because this is a minor bug fix.

Reproduce steps

This reproduces on main by running:

bundle exec ruby -Iactivesupport/lib -Iactivemodel/lib -e 'require "active_model"; account = Class.new { include ActiveModel::Attributes; include ActiveModel::SchematizedJson; attribute :settings; has_json :settings, restricts_access: true }.new; p account.settings.restricts_access'

Checklist

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rafaelfranca

Copy link
Copy Markdown
Member

How can we reproduce the error to know it is fixed by this PR?

@tellodaniel

Copy link
Copy Markdown
Contributor Author

@rafaelfranca

You can reproduce with:

bundle exec ruby -Iactivesupport/lib -Iactivemodel/lib -e 'require "active_model"; account = Class.new { include ActiveModel::Attributes; include ActiveModel::SchematizedJson; attribute :settings; has_json :settings, restricts_access: true }.new; p account.settings.restricts_access'

I updated the description to include this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants