set_public_id can raise IntegrityError when two annotations are added concurrently #2780
Labels
No labels
backend
critical
defect
duplicate
enhancement
fixed
frontend
general
invalid
major
minor
normal
oxjs
pandora_client
python-ox
task
trivial
wontfix
worksforme
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: 0x2620/pandora#2780
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If more than one annotation is added to the same scene concurrently, the
update()
call in Annotation.set_public_id can throwIntegrityError: duplicate key value violates unique constraint "annotation_annotation_public_id_key"
, because there is a race between determining the current highest annotation ID for a scene, and setting that+1 on the new annotation.It's a bit cheesy, but assuming
Annotation.id
starts from0
and increases by1
for each new annotation, I think it would be safe to just define:Another option would be to create a new
SEQUENCE
starting atmax(public_id) + 1
at the time of the upgrade and use that. Both of these make the 'local' part of thepublic_id
globally unique but surely nothing is relying on the first annotation on itemXYZ
beingXYZ/A
?(This isn't hypothetical, users are seeing this error in practice.)
We really want to start with /A for the first annotation per item to keep urls short.
I have not seen this integrity error in a long time. Is there unusually high load at your instance?
creating a sequence per item seams to be the best option to me.
using many sequences in postgres does not perform well, will be using a table instead.
In []changeset:pandora,4976:
Not unusually high load that I could see – it was only happening (regularly) for one user, and I couldn't work out what she was doing differently. Naturally it couldn't be reproduced when I was watching…
Thanks!