-
-
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
Error responses contain strange indexes #1434
Comments
This should be reproducible. Are you sending correct content-type |
I'm also experiencing this issue : an RSpec test file with multiple tests (happy and failure paths) throws in extra indexes in error messages. The 'Content-Type' => 'application/json' header is correctly set. I was able to simulate the issue when adding debug points, although the issue does not always appears for the same tests (so similar to the original reported the issue appears sometimes & sometimes not). Grape params declaration :
I was able to trace it to the 'grape-0.16.2/lib/grape/validations/params_scope.rb:51' path (screenshots taken using rubymine debugger during handling of the 'ordered_quantity' key). Sometimes the @parent.index is incorrectly set to '0' for a declared param of type Hash resulting in the incorrect message "description[0][ordered_quantity]": Most of the times @parent.index is not set which is the correct behavior resulting in the correct message "description[ordered_quantity]": |
seems to be caused by cec42f2 which contains the following code /lib/grape/validations/attributes_iterator.rb:17
In one of my negative tests I provide an empty Array as data for the 'description' parameter of type Hash, which should be detected as invalid data. However as a side-effect of the above code the 'index' key is added, which results in the behavior described in this ticket. Since RSpec switches the test execution order, the behavior is inconsistent, i.e. only occurs after this specific empty Array test was executed... |
I had a look at the original pull request cec42f2. IMHO this implementation is not correct/incomplete:
A naive simple fix for the issue described by this ticket could be : https://github.com/ruby-grape/grape/blob/master/lib/grape/validations/attributes_iterator.rb#L17
This way:
|
I think you should write a bunch of specs @pvmeerbe and try to implement fixes for the failures. |
I can confirm the reported issue does not occur anymore using grape 0.17.0 |
Closing. |
Hello,
I have the following grape endpoint:
When I send the following data:
{"user":{"access_start": null},"filters":[{"id":{"equals":[1, 2]}}]}
and I inspect the error raised by grape(calling as_json on it), I sometimes get errors like this:and sometimes like this:
I am not able to get a consistent behaviour, but the first way seems correct to me. Using grape 0.16.2
Thanks!
The text was updated successfully, but these errors were encountered: