summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 641fbd156..d22a89916 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -36,6 +36,7 @@ import six
import subprocess
import sys
import tempfile
+import time
import xmltodict
import zipfile
@@ -418,9 +419,18 @@ def deserialize_args_for_tasks(sender, kwargs, extra_kwargs=None):
if not isinstance(sender, (tuple, list)): # not task
return sender, kwargs["instance"]
sender = apps.get_model(*sender)
- try:
- instance = sender.objects.get(pk=kwargs['instance'])
- except sender.DoesNotExist:
+ instance = None
+ retried = 0
+ # object can be in cache of another thread but not yet commited
+ # waiting for it
+ while not instance and retried < 6:
+ if retried:
+ time.sleep(.5)
+ if sender.objects.filter(pk=kwargs['instance']).count():
+ instance = sender.objects.get(pk=kwargs['instance'])
+ else:
+ retried += 1
+ if not instance:
return sender, None # object is not here anymore
if extra_kwargs:
for kw in extra_kwargs:
@@ -456,7 +466,9 @@ def cached_label_changed(sender, **kwargs):
# return
# cache.set(cache_key, True, settings.CACHE_TASK_TIMEOUT)
- if not settings.USE_BACKGROUND_TASK:
+ if not settings.USE_BACKGROUND_TASK or not instance.pk \
+ or not sender.objects.filter(pk=instance.pk).count():
+ # no background task or not yet fully saved
return _cached_label_changed(sender, **kwargs)
if getattr(instance, "_cascade_change", False):
@@ -474,7 +486,6 @@ def _cached_label_changed(sender, **kwargs):
if not instance:
return
force_update = kwargs.get('force_update', False)
-
if hasattr(instance, "need_update") and instance.need_update:
force_update = True
instance.skip_history_when_saving = True