Skip to content

Commit

Permalink
Fix photo validation breaking upload transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
DeD1rk committed Oct 26, 2023
1 parent 71c1eb0 commit c30a95a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions website/photos/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", []):
Expand Down

0 comments on commit c30a95a

Please sign in to comment.