Skip to content

Commit

Permalink
started on fixing race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Oct 11, 2024
1 parent 1a49b08 commit e5cd1db
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
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.filter(is_on_wait=False)
return self.registrations.select_for_update().filter(is_on_wait=False)

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

from django.db import transaction
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 @@ -48,6 +49,7 @@ def _is_own_registration(self):
def _is_not_own_registration(self):
return not self._is_own_registration()

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

Expand Down

0 comments on commit e5cd1db

Please sign in to comment.