[openstreetmap/openstreetmap-website] Use `where()` instead of `find()` to prevent RecordNotFound (PR #4203)
ENT8R
notifications at github.com
Fri Aug 25 22:49:58 UTC 2023
When using the Users API to find a set of specific users by their ids and including an id of a user that deleted their account in this set, the request will currently fail with a 404
For example requesting the details of the users with the ids `18597840` **and** `185978900` [fails with a 404](https://www.openstreetmap.org/api/0.6/users?users=18597840,185978900) whereas limiting the query to user `18597840` returns the [correct result](https://www.openstreetmap.org/api/0.6/users?users=18597840)
This happens because user `185978900` deleted their account and `find()` raises an `ActiveRecord::RecordNotFound` "If one or more records cannot be found for the requested ids". <sup><a href="https://api.rubyonrails.org/v7.0.7.2/classes/ActiveRecord/FinderMethods.html#method-i-find">1</a></sup>
Using `where()` to find the users by their ids does not result in an error being raised if (at least) one of the records could not be found.
I also added a fallback for rendering the XML in case no user was found at all (because `@users` is nil in that case which can not be converted to a String)
You can view, comment on, or merge this pull request online at:
https://github.com/openstreetmap/openstreetmap-website/pull/4203
-- Commit Summary --
* Use where instead of find to prevent 404
-- File Changes --
M app/controllers/api/users_controller.rb (2)
M app/views/api/users/index.xml.builder (2)
-- Patch Links --
https://github.com/openstreetmap/openstreetmap-website/pull/4203.patch
https://github.com/openstreetmap/openstreetmap-website/pull/4203.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4203
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4203 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230825/84734ba3/attachment.htm>
More information about the rails-dev
mailing list