Locking the element on take_snapshot to avoid racing condition issues
parent
985838cd1a
commit
50fd9b6161
|
@ -30,6 +30,7 @@ django-ipware==0.1.0
|
||||||
premailer==2.8.1
|
premailer==2.8.1
|
||||||
django-transactional-cleanup==0.1.13
|
django-transactional-cleanup==0.1.13
|
||||||
lxml==3.4.1
|
lxml==3.4.1
|
||||||
|
git+https://github.com/Xof/django-pglocks.git@dbb8d7375066859f897604132bd437832d2014ea
|
||||||
|
|
||||||
# Comment it if you are using python >= 3.4
|
# Comment it if you are using python >= 3.4
|
||||||
enum34==1.0
|
enum34==1.0
|
||||||
|
|
|
@ -37,6 +37,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.paginator import Paginator, InvalidPage
|
from django.core.paginator import Paginator, InvalidPage
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.db import transaction as tx
|
from django.db import transaction as tx
|
||||||
|
from django_pglocks import advisory_lock
|
||||||
|
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.base.utils.db import get_typename_for_model_class
|
from taiga.base.utils.db import get_typename_for_model_class
|
||||||
|
@ -269,6 +270,7 @@ def get_modified_fields(obj:object, last_modifications):
|
||||||
|
|
||||||
return modified_fields
|
return modified_fields
|
||||||
|
|
||||||
|
|
||||||
@tx.atomic
|
@tx.atomic
|
||||||
def take_snapshot(obj:object, *, comment:str="", user=None, delete:bool=False):
|
def take_snapshot(obj:object, *, comment:str="", user=None, delete:bool=False):
|
||||||
"""
|
"""
|
||||||
|
@ -280,6 +282,7 @@ def take_snapshot(obj:object, *, comment:str="", user=None, delete:bool=False):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = make_key_from_model_object(obj)
|
key = make_key_from_model_object(obj)
|
||||||
|
with advisory_lock(key) as acquired_key_lock:
|
||||||
typename = get_typename_for_model_class(obj.__class__)
|
typename = get_typename_for_model_class(obj.__class__)
|
||||||
|
|
||||||
new_fobj = freeze_model_instance(obj)
|
new_fobj = freeze_model_instance(obj)
|
||||||
|
|
Loading…
Reference in New Issue