Skip to content

Commit

Permalink
fixed race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Oct 11, 2024
1 parent 8c05074 commit d6ad239
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/content/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_has_attended(self):
return self.get_participants().filter(has_attended=True)

def get_participants(self):
return self.registrations.select_for_update().filter(is_on_wait=False)
return self.registrations.filter(is_on_wait=False)

def get_waiting_list(self):
"""Number of users on the waiting list"""
Expand Down
6 changes: 3 additions & 3 deletions app/content/views/registration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid

from django.db import transaction
from django.db.transaction import atomic
from django.shortcuts import get_object_or_404
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, status
Expand Down Expand Up @@ -49,7 +49,7 @@ def _is_own_registration(self):
def _is_not_own_registration(self):
return not self._is_own_registration()

@transaction.atomic
@atomic
def create(self, request, *args, **kwargs):
"""Register the current user for the given event."""

Expand All @@ -70,7 +70,7 @@ def create(self, request, *args, **kwargs):
serializer.is_valid(raise_exception=True)

event_id = self.kwargs.get("event_id", None)
event = Event.objects.get(pk=event_id)
event = Event.objects.select_for_update().get(pk=event_id)

registration = super().perform_create(
serializer, event=event, user=request.user
Expand Down

0 comments on commit d6ad239

Please sign in to comment.