editoast: fix work_schedules pagination by ordering on id instead of obj_id - #18749
Merged
Merged
Conversation
…obj_id
WorkSchedule::OBJ_ID is not unique: a work schedule spanning several days (e.g. a multi-night work)
is represented as several rows sharing the same obj_id and track ranges, but with
distinct id, start_date and end_date. Ordering by obj_id therefore sorts the column with ties,
and Postgres gives no guarantee that row order is consistent across queries.
This caused two bugs on GET /work_schedules/group/{id}:
1. Rows tied on obj_id could be ordered differently between two consecutive queries,
so a row could appear on two consecutive results (duplicate) or be skipped entirely.
2. On the last (partial) page, it causes PaginationStats::new's consistency assertion
to panic, and surface as a 502 error.
I suppose because the cumulative count no longer add up to total_count.
Fix: order by WorkSchedule::ID instead of OBJ_ID, same as TrainSchedule already does.
Signed-off-by: Elise Chin <tech.git@swively.fr>
Contributor
|
eckter
approved these changes
Sep 23, 2026
eckter
left a comment
Contributor
There was a problem hiding this comment.
Thanks a lot for the fix!
LGTM for the core script, with the removal of the commented code
eckter
reviewed
Sep 23, 2026
leovalais
approved these changes
Sep 23, 2026
leovalais
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the fix!
- Skip editoast authentification - The local gateway_url does not have api in it, so remove it Signed-off-by: Elise Chin <tech.git@swively.fr>
elise-chin
force-pushed
the
ecn/fix-work-schedules-pagination
branch
from
September 23, 2026 14:18
34c1190 to
eb172c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #16277
Fixes #16270
Description
WorkSchedule::OBJ_IDis not unique: a work schedule spanning several days (e.g. a multi-night work) is represented as several rows sharing the same obj_id and track ranges, but with distinct id, start_date and end_date. Ordering byobj_idtherefore sorts the column with ties, and Postgres gives no guarantee that row order is consistent across queries.This caused two bugs on
GET /work_schedules/group/{id}:obj_idcould be ordered differently between two consecutive queries, so a row could appear on two consecutive results (duplicate) or be skipped entirely.PaginationStats::new's consistency assertion to panic, and surface as a 502 error. I suppose because the cumulative count no longer add up to total_count.Fix: order by
WorkSchedule::IDinstead ofOBJ_ID, same as TrainSchedule already does.Test
To reproduce on
devbranchuv run download-work-schedules.py -u http://localhost:8090/ -g 1 -c -EXAMPLEfooEXAMPLE. You will see this error:+1. Run the same command, and you will see duplicatesOn this branch