Skip to content

Commit

Permalink
wrap get_current in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jul 11, 2023
1 parent f2074e0 commit d240d65
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions edc_sites/model_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.sites.managers import CurrentSiteManager as BaseCurrentSiteManager
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db import models, transaction


class SiteModelMixinError(Exception):
Expand Down Expand Up @@ -41,21 +41,15 @@ def get_site_on_create(self) -> Site:
site = None
if not self.site:
try:
site = Site.objects.get_current()
with transaction.atomic():
site = Site.objects.get_current()
except ObjectDoesNotExist as e:
raise SiteModelMixinError(e)
return site or self.site

def validate_site_against_current(self) -> None:
"""Validate existing site instance matches current_site."""
pass
# current_site = Site.objects.get_current()
# if self.site != current_site:
# site = current_site
# raise SiteModelMixinError(
# f"Invalid attempt to change site! Expected `{self.site}`. "
# f"Tried to change to `{current_site}`. Model=`{self}`. id=`{self.id}`."
# )

class Meta:
abstract = True

0 comments on commit d240d65

Please sign in to comment.