Corrected a hash modification while iterating issue. #2162
Merged
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.
- What is it good for
There is a nasty bug on edge case usage of nested mounted APIs which use a shared class-helper method to abstract the creation of a route. With this fix in place, no errors are raised. Otherwise a
RuntimeError: can't add a new key into hash during iteration
is raised. This is caused by an inline modification of the @setup set inside the Grape::API class. This error is caused by the definition of the helper method in a specific way. The following form causes the issue:while this form works as expected:
- What I did
I just converted the inline set modification into a reassignment of a freshly built set and added a test that proves the bugfix.
- A picture of a cute animal (not mandatory but encouraged)