Repository navigation
fix: Serialize JSON facets with JSON.generate, which ActiveSupport 6.1 doesn't break under json 3 - #11
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSON facets raised
ArgumentError: unknown keyword: quirks_modein apps on Rails 6.1 with the json 3 gem. That includesjson_facet,json_facet_statsand the newchild_facetfrom #10. Glint's Rails 6 CI hit it in https://github.com/culturecode/glint/pull/148.The cause
Query::AbstractJsonFieldFacet#to_paramsandQuery::FieldStats#to_paramsserialized the facet withto_json. ActiveSupport overridesHash#to_json, and ActiveSupport 6.1's encoder passesquirks_modetoJSON.generate, which json 3 removed.With json 3.1.0 and ActiveSupport 6.1.7.10:
What changes
Both now call
JSON.generatedirectly, so the request doesn't depend on what an app's ActiveSupport does toto_json.Testing
spec/api/nested_documents_spec.rbmakesHash#to_jsonraise the samequirks_modeerror, and checks that building achild_facetstill works. Withto_jsonput back, it fails with that error.sunspotsuite onsolr:9.10.1: 1,557 examples, 0 failures, 6 pending.🤖 Generated with Claude Code