Skip to content

Commit

Permalink
Prevent occasional crash during task re-ordering
Browse files Browse the repository at this point in the history
Prevent occasional crash during task re-ordering
  • Loading branch information
shacker committed Mar 25, 2019
1 parent f6d7987 commit 184084c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions todo/views/reorder_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ def reorder_tasks(request) -> HttpResponse:
# Re-prioritize each task in list
i = 1
for id in newtasklist:
task = Task.objects.get(pk=id)
task.priority = i
task.save()
i += 1
try:
task = Task.objects.get(pk=id)
task.priority = i
task.save()
i += 1
except Task.DoesNotExist:
# Can occur if task is deleted behind the scenes during re-ordering.
# Not easy to remove it from the UI without page refresh, but prevent crash.
pass

# All views must return an httpresponse of some kind ... without this we get
# error 500s in the log even though things look peachy in the browser.
Expand Down

0 comments on commit 184084c

Please sign in to comment.