apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

[Bug]: Location categories go missing when the server returns an error

Open Medhansh-741 opened this issue 1 week ago • 2 comments

Summary

During upload, the app suggests categories based on where the picture was taken. If the server answers that lookup with an error, the app thinks there are simply no categories. It doesn't retry and doesn't log anything, so the user just gets no location categories.

The code only looks for results and never checks for an error: https://github.com/commons-app/apps-android-commons/blob/c025f9e/app/src/main/java/fr/free/nrw/commons/mwapi/CategoryApi.kt#L33-L54

Two kinds of errors get lost this way:

  • errors from the MediaWiki API itself (like "maxlag", when the servers are busy). These come back with HTTP 200, so they look like a normal answer.
  • an error status with an empty body, like a bare 503.

The code that calls it already retries a failed lookup: https://github.com/commons-app/apps-android-commons/blob/c025f9e/app/src/main/java/fr/free/nrw/commons/upload/FileProcessor.kt#L219-L235 but it never finds out the lookup failed. And since a place is now looked up only once per upload (#7420), the other pictures from that place miss out too.

Other API calls in the app don't have this problem, because their HTTP client turns these errors into real errors (UnsuccessfulResponseInterceptor). This lookup uses a different client that doesn't.

Steps to reproduce

  1. Pick a picture with a location that has categorized files nearby on beta (I used Delhi).
  2. Make the server answer the location lookup with an error. I did this with a small test-only change that adds maxlag=-1 to the first lookup of each place, so the beta server sends back its real "maxlag" error.
  3. Go to the categories step.

Expected behaviour

The app sees the error, tries again, and shows the location categories once it works.

Actual behaviour

The app treats the error as "nothing found". No retry, no error in the log, no location categories.

This is what beta sent back (HTTP 200):

mediawiki-api-error: maxlag
{"error":{"code":"maxlag","info":"Waiting for 172.16.16.61:3306: 0 seconds lagged.",...},"servedby":"deployment-mediawiki15"}

I also wrote a test on main (c025f9e) that runs the real CategoryApi against a fake server. Both error cases come back as an empty list instead of an error:

API error with HTTP 200: Value counts differ; expected: 0 but was: 1 (latch = 0, values = 1, errors = 0, completions = 1)
HTTP 503, empty body:    Value counts differ; expected: 0 but was: 1 (latch = 0, values = 1, errors = 0, completions = 1)

An error page in plain text (like a 429 from the servers) already shows up as an error, so that case is fine.

Device name

OnePlus CPH2491

Android version

Android 16

Commons app version

main at c025f9e (BetaDebug)

Device logs

Two pictures, London and Delhi. The first lookup of each place got the maxlag error, and the app never tried again:

11-26 02:18:47.193 D/CategoryApi: URL: ...codistancefrompoint=51.510380%7C-0.095580...&maxlag=-1
11-26 02:18:47.223 D/CategoryApi: URL: ...codistancefrompoint=28.644800%7C77.216721...&maxlag=-1
11-26 02:18:48.807 V/OkHttp: mediawiki-api-error: maxlag
11-26 02:18:49.118 V/OkHttp: mediawiki-api-error: maxlag

Screenshots

Categories step after that run: no location categories (normally "New Delhi Railway Station" and "Android sculptures" show up for the Delhi picture).

categories-step

Would you like to work on the issue?

Yes

@nicolas-raoul could you set the type to Bug? I can't set it from my side.

Medhansh-741 avatar Nov 25 '26 22:11 Medhansh-741

Assigned to you, @Medhansh-741! Thanks!

nicolas-raoul avatar Nov 25 '26 22:11 nicolas-raoul

@nicolas-raoul opened #7435 for this. It now reports the error so the existing retry kicks in, tested on beta with a real maxlag error on the phone.

Medhansh-741 avatar Nov 25 '26 23:11 Medhansh-741