Fix tracking race condition
This commit is contained in:
parent
677b4086e5
commit
9a3a9db4ee
|
@ -5,6 +5,7 @@ from django.contrib.auth.models import User, Group
|
|||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.db import transaction
|
||||
from django.db.models import Max
|
||||
from django.db.utils import OperationalError
|
||||
from django.http import HttpResponse, Http404, FileResponse
|
||||
from django.core.files.base import File
|
||||
from django.core.cache import cache
|
||||
|
@ -502,9 +503,10 @@ class StatsViewSet(viewsets.ViewSet, List):
|
|||
except KeyError:
|
||||
raise exceptions.ValidationError(dict(data='This field is required.'))
|
||||
|
||||
@transaction.atomic
|
||||
@action(detail=False, methods=['post'])
|
||||
def track(self, request):
|
||||
try:
|
||||
with transaction.atomic():
|
||||
if 'name' not in request.data:
|
||||
raise exceptions.ValidationError(dict(name='This field is required.'))
|
||||
|
||||
|
@ -542,6 +544,10 @@ class StatsViewSet(viewsets.ViewSet, List):
|
|||
|
||||
return Response(200)
|
||||
|
||||
# keep trying if we hit a "database locked" error
|
||||
except OperationalError:
|
||||
return self.track(request)
|
||||
|
||||
|
||||
class MemberCountViewSet(Base, List):
|
||||
pagination_class = None
|
||||
|
|
Loading…
Reference in New Issue
Block a user