From c30a95acee39f3db260ac59d1c00c19ee7234bac Mon Sep 17 00:00:00 2001 From: Dirk Doesburg Date: Thu, 26 Oct 2023 21:51:16 +0200 Subject: [PATCH] Fix photo validation breaking upload transaction --- website/photos/services.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/photos/services.py b/website/photos/services.py index c2809aa59..67b834e8f 100644 --- a/website/photos/services.py +++ b/website/photos/services.py @@ -5,6 +5,7 @@ from django.contrib import messages from django.core.files import File +from django.db import transaction from django.db.models import BooleanField, Case, ExpressionWrapper, Q, Value, When from django.forms import ValidationError from django.http import Http404 @@ -104,8 +105,9 @@ def _try_save_photo(request, album, file, filename): instance = Photo(album=album) instance.file = File(file, filename) try: - instance.full_clean() - instance.save() + with transaction.atomic(): + instance.full_clean() + instance.save() except ValidationError as e: errors = e.message_dict if "This photo already exists in this album." in errors.get("file", []):