From f22e92132c12a8ecb86675b4d956212e688d5c3e Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 4 Oct 2020 20:47:15 +0200 Subject: [PATCH] Select for update transaction notes, and not only the transaction --- apps/note/models/transactions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index bfe39a42..e0aa30f4 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -3,6 +3,7 @@ from django.core.exceptions import ValidationError from django.db import models, transaction +from django.db.models import F from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -217,6 +218,9 @@ class Transaction(PolymorphicModel): # When source == destination, no money is transferred and no transaction is created return + self.source = Note.objects.select_for_update().get(pk=self.source_id) + self.destination = Note.objects.select_for_update().get(pk=self.destination_id) + # Check that the amounts stay between big integer bounds diff_source, diff_dest = self.validate()