[FIX] runbot: ensure correct batch order in last_batchs compute #1213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
In some environments, the
last_batchsfield was returning batches in a non-deterministic order, even though the backend query was intended to sort them by most recent first. This was due to the use of PostgreSQL'sARRAY_AGGfunction without an explicitORDER BYclause, which does not guarantee the order of elements in the resulting array.This caused the frontend to display batches in the wrong order, despite the backend shell showing them correctly, leading to confusion and inconsistent UI behavior.
Solution:
Explicitly specify the order in the
ARRAY_AGGfunction within the SQL query used in_compute_last_batchs. By addingORDER BY batch.id DESC, we ensure that the array of batch IDs is always sorted from newest to oldest, matching the intended logic and the backend results.