Skip to content

Fix possible IntegrityError when deleting task that is part of a contest - #1470

Merged
prandla merged 2 commits into
cms-dev:mainfrom
e-i-o:bugfix-delete-task
Jul 23, 2025
Merged

Fix possible IntegrityError when deleting task that is part of a contest#1470
prandla merged 2 commits into
cms-dev:mainfrom
e-i-o:bugfix-delete-task

Conversation

@prandla

@prandla prandla commented Jul 18, 2025

Copy link
Copy Markdown
Member

#1065 noticed this bug and fixed it for the "remove task for contest" case. However, the same logic was in two other places that could still cause the error.

For the bug to happen, you need the ID order of the shifted tasks to not match the order they have in the contest. In this case, psycopg apparently attempts to update the tasks in order of ID, which causes an integrity error after the first update, because the updates aren't batched properly.

@prandla

prandla commented Jul 21, 2025

Copy link
Copy Markdown
Member Author

I noticed #469 which seems to also be related to the requirement that num is always in the range 0 to n-1. That issue is probably fixed by now, but evidently keeping nums updated properly isn't trivial. I think it might be simpler to drop this requirement altogether; "move to end" can set num = max(nums) + 1, "move to front" sets num = min(nums) - 1, move up/down already just swap the nums without needing them to be consecutive. This way, moving or deleting things doesn't require fiddling with the numbers on other tasks at all.

@prandla
prandla merged commit 5f111c5 into cms-dev:main Jul 23, 2025
3 checks passed
@prandla
prandla deleted the bugfix-delete-task branch July 23, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants