Corrected a hash modification while iterating issue.#2162
Merged
dblock merged 1 commit intoruby-grape:masterfrom Feb 22, 2021
Merged
Corrected a hash modification while iterating issue.#2162dblock merged 1 commit intoruby-grape:masterfrom
dblock merged 1 commit intoruby-grape:masterfrom
Conversation
98316ed to
4453c15
Compare
dblock
requested changes
Feb 19, 2021
Member
dblock
left a comment
There was a problem hiding this comment.
Doesn't this start adding duplicates into @setup? It's a Set.
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
4453c15 to
c859eee
Compare
Contributor
Author
No, it does not add duplicates, because it's a set. Example: block1 = proc { false }
block2 = proc { true }
setup = Set.new
setup << { method: :default_format, args: [:json], block: block1 }
setup << { method: :default_format, args: [:text], block: block2 }
setup << { method: :default_format, args: [:text], block: block2 }
# =>
# #<Set: {{:method=>:default_format,
# :args=>[:json],
# :block=>#<Proc:0x000055bbcbe3a8f0 (irb):5>},
# {:method=>:default_format,
# :args=>[:text],
# :block=>#<Proc:0x000055bbcb83dce0 (irb):6>}}>
setup = Set.new
setup += [{ method: :default_format, args: [:json], block: block1 }]
setup += [{ method: :default_format, args: [:text], block: block2 }]
setup += [{ method: :default_format, args: [:text], block: block2 }]
# #<Set: {{:method=>:default_format,
# :args=>[:json],
# :block=>#<Proc:0x000055bbcbe3a8f0 (irb):5>},
# {:method=>:default_format,
# :args=>[:text],
# :block=>#<Proc:0x000055bbcb83dce0 (irb):6>}}> |
Member
|
Looks good, thank you. |
Contributor
|
@dblock can you estimate when a new version can be released including this patch? |
Member
|
I can do it this week unless someone gets it before me, add your +1 to #2163 |
This was referenced Mar 8, 2021
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.
- 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 iterationis 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)