jrief / django-admin-sortable2

Generic drag-and-drop ordering for objects in the Django admin interface
https://django-admin-sortable2.readthedocs.io/en/latest/
Other
753 stars 179 forks source link

fix index on parallel queries #373

Open intsynko opened 1 year ago

intsynko commented 1 year ago

Fix sorting in parallel requests

Problem:

When you draging several lines in few seconds and parallel request running to change position - its raise an unrepetable reading and the sort index in database became not unique. For example we have an table:

a 1 b 2 c 3 d 4 e 5

and two parallel requests

after first requests table will be:

a 1 b 4 c 2 d 3 e 5

after second request table will be:

a 1 b 4 c 4 d 5 e 3

Problem is duplicating sort index 4 in table. It apperas becouse second request had read table before changes from first query was applied - so second request moved e to 3d position and changed indexes for d and c as +1.

Solition

To avoid this case we will lock all the range of changable rows

intsynko commented 1 year ago

@jrief pls check it when you will have a time