-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Spec for Array types leaking index into subsequent Hash validations #1313
Conversation
Thanks for the spec, lets get this fixed, cc: @towanda |
I'm looking into this, and I've made some progress, though it's actually quite tricky to figure out. Will let you know if I give up 😝 |
Ok, so, there's some bad news. Basically with the way the code is currently structured it is impossible to get the correct array indices for parameter validations. This is because each params do
group :children, type: Array do
requires :name
group :parents, type: Array do
requires :name
end
end When we get to validating the Here are a few options: 1. Do the restructure.Pros:
Cons:
2. Revert the array indices featureThis sucks, but as is the feature is completely broken: it leaks into non-array scopes, and always shows [0] for every index, which is IMO worse than showing nothing at all. Pros:
Cons:
3. Show array indices only for the innermost scope.Pros:
Cons:
ConclusionThese options are not mutually exclusive. We could start by doing 2. or 3., but keep in mind to properly address iterating through scoped parameters in a way that preserves context at some point in the future (like whenever someone has the time and inclination). Personally I feel like option 3 strikes a good balance by preserving what feels to me to be the most common use case of the feature with minimal effort. But maybe given that it doesn't work properly in all cases and relies on some "hacky" stuff, it would be best to remove it until it can be done correctly? |
I vote for doing (2) and thus undoing a regression, then documenting very thoroughly what we want in an issue with failing specs so that we can fix it properly (which will take a brave person). |
Hi. First of all, sorry I abandoned this back in March. We were under some time pressure so we ended up reverting to 0.13 and rolling with that. We've recently had another look at this and it's still causing us problems, so I was wondering if your preference was still to yank the array indices? If you're still happy to revert the bug (though at this point I realize it's been several releases so people may be depending on the broken behaviour), I'll go ahead and do a PR. |
a9f8a93
to
51b9b77
Compare
Generated by 🚫 danger |
51b9b77
to
2131dd5
Compare
This confirms the issue raised in this comment: ruby-grape#1131 (comment)
2131dd5
to
a9c3d2e
Compare
Sorry again. On closer inspection it looks like this has already been fixed by #1463. The specs in this PR now pass and I've rebased them against master. If you think it's worthwhile keeping a test against the leakage you could keep them, otherwise I'm happy to close this off. Thanks! |
Lets keep the tests, merging. |
This confirms the issue raised in this comment: #1131 (comment) by @Galkon
It was quite difficult to track down when this issue was occurring because it actually depends on a required
Array
parameter being defined before theHash
parameter in theparams
block. Somehow the existence of anindex
is leaking between the parameters.@Galkon and I spent a bit of time trying to find the source of the issue, but decided to open a PR with the spec in case it turned out to be much easier for someone with a deeper familiarity with the codebase.