Weblate API returns empty results instead of 404 when page exceeds total count
0 reputation · 27 Aug 2023, 22:22 UTC
0 reputation · 27 Aug 2023, 22:22 UTC
When querying Weblate's REST API for translation units with a page parameter that exceeds the total number of available pages, the endpoint returns a 200 OK response containing an empty results array rather than a 404 Not Found. This behavior differs from typical REST conventions where requesting a non-existent resource yields a 4xx status code.
The API accepts a per_page parameter (default 20) to control page size. Increasing this value reduces the number of requests needed to fetch a large dataset, but offset-based pagination with high per_page values may introduce ORM overhead and memory pressure on the database layer. No official guidance documents the optimal upper bound for per_page or whether values above 100 cause measurable latency.
Weblate's built-in Django Paginator relies exclusively on LIMIT/OFFSET. For datasets with millions of translation units, deep pagination becomes progressively slower and can produce duplicate or missing results if rows are inserted or deleted between requests. A cursor-based alternative is not exposed through the standard API.
What is the recommended maximum per_page value before ORM overhead degrades response time? Does the empty-results-on-overflow behavior constitute a bug or intentional design? Are there plans to introduce cursor-based pagination for translation unit endpoints?
37275 reputation · 28 Aug 2023, 09:45 UTC
Treat the reported behavior as a pagination-contract issue to verify, not automatically as a bug: Weblate returns HTTP 200 with an empty results array for a page beyond the last page, and there is no published universal per_page maximum or confirmed cursor-based pagination plan for translation-unit endpoints. Stop pagination when next is null; do not stop only because results is empty.
| Item | Status | Notes |
|---|---|---|
200 empty results on overflow page | Reported; version-specific | Standard Django REST Framework page-number pagination normally raises 404 for invalid or out-of-range pages, so Weblate or the view may be handling EmptyPage differently. Confirm on the deployed version. |
Recommended maximum per_page | No official threshold | Cost depends on database, indexes, ordering, filters, offset, and row size. Benchmark instead of adopting a number. |
| Cursor-based pagination for translation units | No public plan known | Standard pagination is page/per_page with LIMIT/OFFSET; deep offsets can be slow and unstable when rows are inserted or deleted between requests. |
page=1 and page=last+1, where last is computed from count and per_page in the first response. Compare status, count, next, previous, and results length.next=null and empty results, update the client to terminate on next=null; treat empty results alone as ambiguous.per_page above the current default, benchmark on a staging copy in small steps. Enable Django query logging only in non-production, and compare query count/time and response latency across offsets.WEBLATE_API=https://weblate.example.com/api
PATH=projects/p/components/c/translations/l/units/
curl -sS -i --get --data-urlencode page=1 --data-urlencode per_page=20 $WEBLATE_API/$PATH
curl -sS -i --get --data-urlencode page=2 --data-urlencode per_page=20 $WEBLATE_API/$PATHReplace placeholders. Use the first response's count to compute the overflow page, then repeat with that page. Do not send write requests.
count, next, previous, and results.per_page ceiling, Weblate's cursor-pagination roadmap, and whether empty overflow is documented as intentional.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.