From b19151e144e1b6766b528750a99a5fca5f7ace8c Mon Sep 17 00:00:00 2001 From: Happy Felix Chukwuma Date: Mon, 2 Dec 2024 09:48:50 +0100 Subject: [PATCH] atomicize slugHistory creation --- server/apps/research/models/article.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/apps/research/models/article.py b/server/apps/research/models/article.py index 6172bf2..72cca9d 100644 --- a/server/apps/research/models/article.py +++ b/server/apps/research/models/article.py @@ -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" @@ -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