thewca / worldcubeassociation.org

All of the code that runs on worldcubeassociation.org
https://www.worldcubeassociation.org/
GNU General Public License v3.0
324 stars 175 forks source link

No results when querying API /search/users route for users without an avatar, but normal results are present when just querying /search #5942

Closed louismeunier closed 3 years ago

louismeunier commented 3 years ago

Describe the bug When querying the /search/users?q={query}, users without an avatar (not even the default avatar; simply no avatar at all) return no real data (simply return the default json {"result":[ ]}). However, when using the more general /search?q={query} on the same people, the expected response is returned. In addition, making a request to /users/:id with these same no-avatar individuals returns a 404 error code, and a json response of {"user":null}.

To Reproduce Steps to reproduce the behavior:

  1. Make a GET request to https://worldcubeassociation.org/api/v0/search/users?q={query}, where query is the WCA id of someone with no avatar. I only tested this with the ids 2015BONE01, 2019AGAR01, and 2019NAGA01, as they were all on the first two pages of the WCA website.
  2. As you'll see, it won't return what you would expect if you made the same query with an id that does have an avatar, default or not.
  3. Making the same request but with /search?q={query} will return the expected response, albeit it with a null for "created_at" and "updated_at".
  4. Making the same type of request but to /users:id also returns an empty json.

Expected behavior I would expect that making this search would return the same json format as would making a request to any other id. I can only assume it has to do with either the lack of avatar or null "created_at" and "updated_at" keys. However, when making the more general /search?q=query request, the "avatar" keys for the individuals listed above did have values, linking to the default "no avatar" picture. That leads me to assume that the lack of avatar on the main website is not the cause of this issue but rather a side effect.

Screenshots https://imgur.com/gallery/EE4TRPN

Desktop (please complete the following information):

Smartphone (please complete the following information): I don't believe this is relevant in this case.

Additional context I experienced these bugs both in an isolated API rest client, Insomnia, as well as in the browser using a XMLHttpRequest. At first, I thought it may have to do with older IDs, but 2019AGAR01 proves otherwise. I also believed that it may have to do with only having competed once, and then never again, as they would not have ever signed into the WCA website to register again and therefore may not be registered as a user. 2009NAGA01, again, shows that this is not necessarily correct.

louismeunier commented 3 years ago

After looking into a bit more, this MAY be related to #266, but I'm really not sure.

jonatanklosko commented 3 years ago

Hey Louis, thanks for the detailed report. What you described is actually expected, but it sure may be confusing. We have two kinds of identity: a person (= WCA results profile) and a user (=user account). For historical reasons not every person has an associated user account. Users may connect their account to the corresponding WCA profile. Every profile with an avatar does have a user account, because it's either connected to a real user account or to so called dummy user account (which actually stores the avatar). This is mostly noticeable for old WCA profiles, as now most competitions use the WCA registration platform and users are more likely to connect their account to their profile. Hopefully we will eventually have this discrepancy removed.

If you're looking for a way to search/retrieve WCA profile data, then the endpoints would be /api/v0/persons?q={query} and /api/v0/persons/:wca_id.

Let me know if you have any further questions!

louismeunier commented 3 years ago

Thank you for the reply, having reread routes.rb, I understand now. I mostly found it odd that these non-user accounts had avatar key/values, but none shown on the website. Thanks again!