mirror of
https://github.com/suitenumerique/meet.git
synced 2026-10-20 11:41:35 +00:00
9bc712009a
Before this commit, a room update and a soft deletion racing each other could leave the room active. Both `perform_update`s now re-read the room with `SELECT ... FOR UPDATE` inside a transaction to avoid this race condition.
18 lines
485 B
Python
18 lines
485 B
Python
"""Row locks guarding the API write paths."""
|
|
|
|
import contextlib
|
|
|
|
from django.db import transaction
|
|
|
|
from core import models
|
|
from core.api.exceptions import ensure_room_not_deleted
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def room_locked_for_update(room):
|
|
"""Lock a room's row for the duration of a write."""
|
|
with transaction.atomic():
|
|
locked_room = models.Room.all_objects.select_for_update().get(pk=room.pk)
|
|
ensure_room_not_deleted(locked_room)
|
|
yield locked_room
|