CORD-1867 prevent synchronizer from setting updated timestamps backward
Change-Id: I275111e3cffc08f067b842ab6d4d7e253c9c52c4
(cherry picked from commit 548b5540c32527356fd17a05e5639d44a4d75b5a)
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions/base.py b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
index 431de3f..93f4581 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/base.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
@@ -82,7 +82,7 @@
def xproto_api_type(field):
try:
if (unquote(field['options']['content_type'])=='date'):
- return 'float'
+ return 'double'
except KeyError:
pass
diff --git a/xos/core/models/attic/xosbase_header.py b/xos/core/models/attic/xosbase_header.py
index b3efde4..1840f5e 100644
--- a/xos/core/models/attic/xosbase_header.py
+++ b/xos/core/models/attic/xosbase_header.py
@@ -35,6 +35,11 @@
import redis
from redis import ConnectionError
+from xosconfig import Config
+from multistructlog import create_logger
+
+log = create_logger(Config().get('logging'))
+
XOS_GLOBAL_DEFAULT_SECURITY_POLICY = True
def date_handler(obj):
diff --git a/xos/core/models/attic/xosbase_model.py b/xos/core/models/attic/xosbase_model.py
index 6ee617f..022ede0 100644
--- a/xos/core/models/attic/xosbase_model.py
+++ b/xos/core/models/attic/xosbase_model.py
@@ -135,6 +135,12 @@
if (caller_kind!="synchronizer") or always_update_timestamp:
self.updated = timezone.now()
+ else:
+ # We're not auto-setting timestamp, but let's check to make sure that the caller hasn't tried to set our
+ # timestamp backward...
+ if (self.updated != self._initial["updated"]) and ((not kwargs.get("update_fields")) or ("updated" in kwargs.get("update_fields"))):
+ log.info("Synchronizer tried to change `updated` timestamp on model %s from %s to %s. Ignored." % (self, self._initial["updated"], self.updated))
+ self.updated = self._initial["updated"]
with transaction.atomic():
self.verify_live_keys(update_fields = kwargs.get("update_fields"))
diff --git a/xos/synchronizers/new_base/event_loop.py b/xos/synchronizers/new_base/event_loop.py
index 2919d26..4e392bb 100644
--- a/xos/synchronizers/new_base/event_loop.py
+++ b/xos/synchronizers/new_base/event_loop.py
@@ -296,7 +296,8 @@
try:
o.backend_status = o.backend_status[:1024]
o.save(update_fields=['backend_status',
- 'backend_register', 'updated'])
+ 'backend_register'],
+ always_update_timestamp=True)
except BaseException as e:
self.log.exception(
"Could not update backend status field!", e=e)