Skip to content
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

[Bugfix] Handle deeply-nested dependent params #1661

Merged
merged 3 commits into from
Jul 14, 2017

Conversation

rnubel
Copy link
Contributor

@rnubel rnubel commented Jul 13, 2017

Addresses #1659. The core issue was that param validations are a flat list, and the tree structure was only enforced by the recursion in should_validate?. When I moved the dependency check into the actual validator, the structure was no longer respected past one level deep. To resolve, I've added a similar recursive check into ParamsScope#meets_dependency?. I also added a few more test cases onto @jnardone's repro to test out the behavior works with arrays and nested arrays.

Joe Nardone and others added 3 commits July 13, 2017 12:25
Behind the scenes, each call to `requires` or other params DSL method
pushes an entry onto a flat list of validators. The nesting structure
that your parameters can take on is tracked as an up-tree separately
on each scope, but that relationship isn't used to traverse the validations.
So, when I moved the dependency checking out of `should_validate?` and into
the actual validation, the `given` dependency stopped taking effect after
you nested parameters more than one level deep underneath.

To restore the behavior, I made the validation check recursively upwards
to see if it should or should not validate that scope.
@dblock
Copy link
Member

dblock commented Jul 14, 2017

Thanks for this!

@jnardone jnardone mentioned this pull request Jul 21, 2017
jdurand pushed a commit to jdurand/grape that referenced this pull request Jan 25, 2019
* Repro issue ruby-grape#1659

* [Fix] Handle deeply-nested dependencies with `given`.

Behind the scenes, each call to `requires` or other params DSL method
pushes an entry onto a flat list of validators. The nesting structure
that your parameters can take on is tracked as an up-tree separately
on each scope, but that relationship isn't used to traverse the validations.
So, when I moved the dependency checking out of `should_validate?` and into
the actual validation, the `given` dependency stopped taking effect after
you nested parameters more than one level deep underneath.

To restore the behavior, I made the validation check recursively upwards
to see if it should or should not validate that scope.

* Add changelog entry.
@braktar braktar mentioned this pull request Aug 20, 2020
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.

2 participants