Skip to content

Commit

Permalink
atomicize slugHistory creation
Browse files Browse the repository at this point in the history
  • Loading branch information
happychuks committed Dec 2, 2024
1 parent 092f198 commit b19151e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/apps/research/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
from bs4 import BeautifulSoup
import uuid
from django.db import transaction

def get_default_thumb():
return f"{settings.MEDIA_URL}images/2077-Collective.png"
Expand Down Expand Up @@ -95,10 +96,11 @@ def save(self, *args, **kwargs):
# Then check if we need to create slug history
if old_instance.slug and old_instance.slug != self.slug:
# Only create history if the slug actually changed and isn't empty
ArticleSlugHistory.objects.create(
article=self,
old_slug=old_instance.slug
)
with transaction.atomic():
ArticleSlugHistory.objects.create(
article=self,
old_slug=old_instance.slug
)
except Article.DoesNotExist:
pass

Expand Down

0 comments on commit b19151e

Please sign in to comment.