Skip to content

Commit

Permalink
Event registration race condition (#902)
Browse files Browse the repository at this point in the history
* started on fixing race condition

* fixed race condition
  • Loading branch information
MadsNyl authored Oct 11, 2024
1 parent c44e910 commit 17b2483
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/content/views/registration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid

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

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

Expand All @@ -68,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 17b2483

Please sign in to comment.