-
Notifications
You must be signed in to change notification settings - Fork 361
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
Fix format lookup when JSON or XML are defined as acronyms #361
Conversation
For custom 3rd-party formats the implementation falls back to const_get after camelizing the MIME type reference. Resolves Shopify/shopify-api-ruby#683
ActiveSupport::Inflector.inflections do |inflect| | ||
# N.B. It's not yet possible to use the public ActiveSupport::Inflector::Inflections#clear | ||
# API because it doesn't reset @acronyms to be a Hash (the default value), | ||
# instead it sets an empty array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Planning to contribute a PR to Rails shortly to fix this.
Update: rails/rails#42475
Two of the builds are failing because |
This issue has been automatically marked as stale because it has not been commented on for at least three months. If it is an issue and you can still reproduce this error on the If it is a pull request and you are still interested on having it merged please make sure it can be merged clearly. Thank you for all your contributions. |
I think this is still an issue |
I don't think this is the right fix unfortunately. This removes the possibility of people to register they own format since they would have to modify that BUILT_IN constant. If we want to allow people to change the inflector of those formats and still have active resource working it would be better for us to stop using |
Related to rails#361 Add special-case treatment of JSON and XML acronyms by declaring aliases for the `JsonFormat` and `XmlFormat` constants. In addition to the aliases, this commit also includes test coverage to cover existing behavior. The original PR included a comment citing that `ActiveSupport::Inflector::Inflections#clear` was not working as expected. It was resolved by [a76344f][], which was merged into `main` prior to the `7.0.0` release. Since the CI matrix currently includes `7-0-stable` as the minimum version, the code can rely on the resolved behavior. [a76344f]: rails/rails@a76344f
I've opened #416 as a re-submission of this proposal. |
Related to rails#361 Add special-case treatment of JSON and XML acronyms by declaring aliases for the `JsonFormat` and `XmlFormat` constants. In addition to the aliases, this commit also includes test coverage to cover existing behavior. The original PR included a comment citing that `ActiveSupport::Inflector::Inflections#clear` was not working as expected. It was resolved by [a76344f][], which was merged into `main` prior to the `7.0.0` release. Since the CI matrix currently includes `7-0-stable` as the minimum version, the code can rely on the resolved behavior. [a76344f]: rails/rails@a76344f
Related to rails#361 Add special-case treatment of JSON and XML acronyms by declaring aliases for the `JsonFormat` and `XmlFormat` constants. In addition to the aliases, this commit also includes test coverage to cover existing behavior. The original PR included a comment citing that `ActiveSupport::Inflector::Inflections#clear` was not working as expected. It was resolved by [a76344f][], which was merged into `main` prior to the `7.0.0` release. Since the CI matrix currently includes `7-0-stable` as the minimum version, the code can rely on the resolved behavior. [a76344f]: rails/rails@a76344f
When JSON or XML are defined as acronyms the format lookup fails:
The proposed solution uses a hash to lookup built-in formats. For custom formats the implementation falls back to
const_get
after camelizing the MIME type reference. I didn't find many public examples of custom formats, so not sure these are widely used.Here's an example of this issue in the wild, from the
shopify_api
gem:Shopify/shopify-api-ruby#683