<p dir="auto">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<br>
For example requesting the details of the users with the ids <code class="notranslate">18597840</code> <strong>and</strong> <code class="notranslate">185978900</code> <a href="https://www.openstreetmap.org/api/0.6/users?users=18597840,185978900" rel="nofollow">fails with a 404</a> whereas limiting the query to user <code class="notranslate">18597840</code> returns the <a href="https://www.openstreetmap.org/api/0.6/users?users=18597840" rel="nofollow">correct result</a><br>
This happens because user <code class="notranslate">185978900</code> deleted their account and <code class="notranslate">find()</code> raises an <code class="notranslate">ActiveRecord::RecordNotFound</code> "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" rel="nofollow">1</a></sup></p>
<p dir="auto">Using <code class="notranslate">where()</code> 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.<br>
I also added a fallback for rendering the XML in case no user was found at all (because <code class="notranslate">@users</code> is nil in that case which can not be converted to a String)</p>
<hr>
<h4>You can view, comment on, or merge this pull request online at:</h4>
<p> <a href='https://github.com/openstreetmap/openstreetmap-website/pull/4203'>https://github.com/openstreetmap/openstreetmap-website/pull/4203</a></p>
<h4>Commit Summary</h4>
<ul>
<li><a href="https://github.com/openstreetmap/openstreetmap-website/pull/4203/commits/b9c85c269726faad3c2613b37f01683c8b59f5c6" class="commit-link">b9c85c2</a> Use where instead of find to prevent 404</li>
</ul>
<h4 style="display: inline-block">File Changes </h4> <p style="display: inline-block">(<a href="https://github.com/openstreetmap/openstreetmap-website/pull/4203/files">2 files</a>)</p>
<ul>
<li>
<strong>M</strong>
<a href="https://github.com/openstreetmap/openstreetmap-website/pull/4203/files#diff-52cb10dc1aabfdb745ff2c590fb82ce44f6f1078750119a2b1305505475f7909">app/controllers/api/users_controller.rb</a>
(2)
</li>
<li>
<strong>M</strong>
<a href="https://github.com/openstreetmap/openstreetmap-website/pull/4203/files#diff-303945c2adc67f0e682ec37575d44165de2219662b1351b13101eaef4cd2f1fc">app/views/api/users/index.xml.builder</a>
(2)
</li>
</ul>
<h4>Patch Links:</h4>
<ul>
<li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/4203.patch'>https://github.com/openstreetmap/openstreetmap-website/pull/4203.patch</a></li>
<li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/4203.diff'>https://github.com/openstreetmap/openstreetmap-website/pull/4203.diff</a></li>
</ul>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4203">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLL4CVLRB3WKKPSBFT3XXETZNANCNFSM6AAAAAA37CXSXM">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLNZ6PP3EMOFYIQTAQTXXETZNA5CNFSM6AAAAAA37CXSXOWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHG6U6GAU.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4203</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4203",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4203",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>