Skip to content

fix: Serialize JSON facets with JSON.generate, which ActiveSupport 6.1 doesn't break under json 3 - #11

Merged
njakobsen merged 1 commit into
masterfrom
json-facet-generate
Oct 28, 2026
Merged

njakobsen merged 1 commit into
masterfrom
json-facet-generate

Conversation

@njakobsen

Copy link
Copy Markdown
Member

JSON facets raised ArgumentError: unknown keyword: quirks_mode in apps on Rails 6.1 with the json 3 gem. That includes json_facet, json_facet_stats and the new child_facet from #10. Glint's Rails 6 CI hit it in https://github.com/culturecode/glint/pull/148.

The cause

Query::AbstractJsonFieldFacet#to_params and Query::FieldStats#to_params serialized the facet with to_json. ActiveSupport overrides Hash#to_json, and ActiveSupport 6.1's encoder passes quirks_mode to JSON.generate, which json 3 removed.

With json 3.1.0 and ActiveSupport 6.1.7.10:

{ :name => { :type => "terms" } }.to_json  # ArgumentError: unknown keyword: quirks_mode
JSON.generate({ :name => { :type => "terms" } })  # {"name":{"type":"terms"}}

What changes

Both now call JSON.generate directly, so the request doesn't depend on what an app's ActiveSupport does to to_json.

Testing

  • A new example in spec/api/nested_documents_spec.rb makes Hash#to_json raise the same quirks_mode error, and checks that building a child_facet still works. With to_json put back, it fails with that error.
  • Full sunspot suite on solr:9.10.1: 1,557 examples, 0 failures, 6 pending.

🤖 Generated with Claude Code

…6.1 doesn't break under json 3

Root cause: `Query::AbstractJsonFieldFacet#to_params` and `Query::FieldStats#to_params` serialized the facet with `to_json`. ActiveSupport overrides `Hash#to_json`, and ActiveSupport 6.1's encoder passes `quirks_mode` to `JSON.generate`, which json 3 no longer accepts, so any JSON facet, including `child_facet`, raised `ArgumentError: unknown keyword: quirks_mode` in an app on Rails 6.1 with json 3. Glint's Rails 6 CI hit it.

Both now call `JSON.generate`, which doesn't depend on what an app's ActiveSupport does to `to_json`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@njakobsen
njakobsen merged commit 2548acb into master Oct 28, 2026
182 checks passed
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