From 5114076afa2f4a97944ddaa30988383c4bd09b30 Mon Sep 17 00:00:00 2001 From: James Polley Date: Wed, 9 Aug 2017 12:27:41 +1000 Subject: [PATCH] Make review changes atomic This follows from investigations in https://rt.lca2018.org/Ticket/Display.html?id=283&results=eac0bd3c49f782d054f87d6b160ca36b; in short, it seems that because this very long and complex method creates several different objects at differnt times, the DB has been getting out of sync; there are more votes recorded then there are reviews, becuase the table that stores the vote count is updated before the table that stores the vote and review information This change is intended to make this operation (and the other operations that the revew_detail handler performs) atomic, to prevent things getting further out of step. It does *not* fix the existing incosistency. review_delete has been atomicified as well as it likely needs the same treatment, but this has not been examined in detail. --- vendor/symposion/reviews/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vendor/symposion/reviews/views.py b/vendor/symposion/reviews/views.py index 294913d6..fe8e2ba9 100644 --- a/vendor/symposion/reviews/views.py +++ b/vendor/symposion/reviews/views.py @@ -4,6 +4,7 @@ import random from django.contrib.auth.decorators import login_required from django.core.mail import send_mass_mail +from django.db import transaction from django.db.models import Q from django.http import HttpResponse from django.http import HttpResponseBadRequest, HttpResponseNotAllowed @@ -325,6 +326,7 @@ def review_admin(request, section_slug): # FIXME: This view is too complex according to flake8 @login_required +@transaction.atomic def review_detail(request, pk): proposals = ProposalBase.objects.select_related("result").select_subclasses() @@ -451,6 +453,7 @@ def review_detail(request, pk): @login_required @require_POST +@transaction.atomic def review_delete(request, pk): review = get_object_or_404(Review, pk=pk) section_slug = review.section