Add raise_on_blank_find_param
resource setting
#344
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.
The problem comes from #329
That is a bit curios, but
json_api_client
returns an array from.find
method, always.The history of this fact was discussed here
So, when we searching for a single resource by primary key, we typically write the things like
The next thing which we need to notice -
json_api_client
will just interpolate the incoming.find
param to the end of API URL, just like that:What will happen if we pass the blank id (nil or empty string) to the
.find
method then?.. Yeah,json_api_client
will try to call the INDEX API endpoint instead of SHOW one:Lets sum all together - in case if
id
comes blank (from CGI for instance), we can silently receive theadmin
variable equal to some existing resource, with all the consequences.Even worse,
admin
variable can equal to random resource, depends on ordering applied by INDEX endpoint.If you prefer to get
JsonApiClient::Errors::NotFound
raised, please define in your base Resource class: