[repository] use utcnow instead of now for some internal timetamps (closes #1988458) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Oct 2011 15:55:15 +0200
branchstable
changeset 7922 d307c3817782
parent 7921 a93e2ed5877a
child 7923 ece4bc9b9314
[repository] use utcnow instead of now for some internal timetamps (closes #1988458)
misc/migration/3.13.8_Any.py
schemas/base.py
server/repository.py
server/sources/__init__.py
server/sources/native.py
--- a/misc/migration/3.13.8_Any.py	Fri Oct 07 15:55:14 2011 +0200
+++ b/misc/migration/3.13.8_Any.py	Fri Oct 07 15:55:15 2011 +0200
@@ -1,2 +1,5 @@
+change_attribute_type('CWCache', 'timestamp', 'TZDatetime')
+change_attribute_type('CWUser', 'last_login_time', 'TZDatetime')
+change_attribute_type('CWSource', 'latest_retrieval', 'TZDatetime')
 drop_attribute('CWSource', 'synchronizing')
 add_attribute('CWSource', 'in_synchronization')
--- a/schemas/base.py	Fri Oct 07 15:55:14 2011 +0200
+++ b/schemas/base.py	Fri Oct 07 15:55:15 2011 +0200
@@ -41,7 +41,7 @@
     upassword = Password(required=True) # password is a reserved word for mysql
     firstname = String(maxsize=64)
     surname   = String(maxsize=64)
-    last_login_time  = Datetime(description=_('last connection date'))
+    last_login_time = TZDatetime(description=_('last connection date'))
     in_group = SubjectRelation('CWGroup', cardinality='+*',
                                constraints=[RQLConstraint('NOT O name "owners"')],
                                description=_('groups grant permissions to the user'))
@@ -251,7 +251,7 @@
 
     name = String(required=True, unique=True, maxsize=128,
                   description=_('name of the cache'))
-    timestamp = Datetime(default='NOW')
+    timestamp = TZDatetime(default='NOW')
 
 
 class CWSource(EntityType):
@@ -277,7 +277,7 @@
     # may changes when sources are specified
     url = String(description=_('URLs from which content will be imported. You can put one url per line'))
     parser = String(description=_('parser to use to extract entities from content retrieved at given URLs.'))
-    latest_retrieval = Datetime(description=_('latest synchronization time'))
+    latest_retrieval = TZDatetime(description=_('latest synchronization time'))
     in_synchronization = TZDatetime(description=_('start timestamp of the currently in synchronization, or NULL when no synchronization in progress.'),
                                     default=False)
 
--- a/server/repository.py	Fri Oct 07 15:55:14 2011 +0200
+++ b/server/repository.py	Fri Oct 07 15:55:15 2011 +0200
@@ -890,7 +890,7 @@
           deleted since the given timestamp
         """
         session = self.internal_session()
-        updatetime = datetime.now()
+        updatetime = datetime.utcnow()
         try:
             modentities, delentities = self.system_source.modified_entities(
                 session, etypes, mtime)
--- a/server/sources/__init__.py	Fri Oct 07 15:55:14 2011 +0200
+++ b/server/sources/__init__.py	Fri Oct 07 15:55:15 2011 +0200
@@ -65,13 +65,13 @@
         self.ttl = timedelta(seconds=ttl)
 
     def __setitem__(self, key, value):
-        dict.__setitem__(self, key, (datetime.now(), value))
+        dict.__setitem__(self, key, (datetime.utcnow(), value))
 
     def __getitem__(self, key):
         return dict.__getitem__(self, key)[1]
 
     def clear_expired(self):
-        now_ = datetime.now()
+        now_ = datetime.utcnow()
         ttl = self.ttl
         for key, (timestamp, value) in self.items():
             if now_ - timestamp > ttl:
--- a/server/sources/native.py	Fri Oct 07 15:55:14 2011 +0200
+++ b/server/sources/native.py	Fri Oct 07 15:55:15 2011 +0200
@@ -972,7 +972,7 @@
             extid = b64encode(extid)
         uri = 'system' if source.copy_based_source else source.uri
         attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
-                 'source': uri, 'asource': source.uri, 'mtime': datetime.now()}
+                 'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
         self.doexec(session, self.sqlgen.insert('entities', attrs), attrs)
         # insert core relations: is, is_instance_of and cw_source
         try:
@@ -1002,7 +1002,7 @@
             self.index_entity(session, entity=entity)
         # update entities.mtime.
         # XXX Only if entity.__regid__ in self.multisources_etypes?
-        attrs = {'eid': entity.eid, 'mtime': datetime.now()}
+        attrs = {'eid': entity.eid, 'mtime': datetime.utcnow()}
         self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs)
 
     def delete_info_multi(self, session, entities, uri):
@@ -1019,7 +1019,7 @@
         if entities[0].__regid__ not in self.multisources_etypes:
             return
         attrs = {'type': entities[0].__regid__,
-                 'source': uri, 'dtime': datetime.now()}
+                 'source': uri, 'dtime': datetime.utcnow()}
         for entity in entities:
             extid = entity.cw_metainformation()['extid']
             if extid is not None:
@@ -1173,7 +1173,7 @@
         table when some undoable transaction is started
         """
         ueid = session.user.eid
-        attrs = {'tx_uuid': uuid, 'tx_user': ueid, 'tx_time': datetime.now()}
+        attrs = {'tx_uuid': uuid, 'tx_user': ueid, 'tx_time': datetime.utcnow()}
         self.doexec(session, self.sqlgen.insert('transactions', attrs), attrs)
 
     def _save_attrs(self, session, entity, attrs):