Repository: ckan/ckan

Issue:
Modifying resource doesn't update it's last updated timestamp
Resources show their creation date and last updated date which are the same. If the resource is modified, the last updated date should change but it is not updated.



Discussion:
related to #1567 and would be fixed if I change #1921 to add the last_modified field to resource_show. Is there a reason this field wasn't included in resource_show?

'last_modified' in not set anywhere in CKAN core, this was (or is) supposed to be set by extensions like [ckanext-archiver](https://github.com/ckan/ckanext-archiver/blob/eb3f5d183a33c2286cf90b36bc7d2ca09bd13178/ckanext/archiver/tasks.py#L445). If I'm not mistaken it refers to changes on the original file, not the CKAN resource metadata, so it looks like there is more work involved than originally thought.

Moving to 2.4.

I think we should update this value when users upload files too. It's displayed to end users as the resource's "last updated" date, and users expect that date to change when they upload a new file.

I think the meaning and presentation of the fields should be more clear and consistent.

last_modified: the date and time when the actual data has been last changed
revision_timestamp: the date and time when the resource metadata has been last changed

If this is the correct meaning for the fields, the visual label on the templates for the resource should be consistent with that:

last_modified -> "Data last updated"
revision_timestamp -> "Metadata last updated"

Currently these fields are used interchangeably to display the same label "Last updated". See

`<td>{{ h.render_datetime(res.last_modified) or h.render_datetime(res.revision_timestamp) or h.render_datetime(res.created) or _('unknown') }}</td>`
https://github.com/ckan/ckan/blob/master/ckan/templates/package/resource_read.html#L158


Resolving patch:
diff --git a/ckan/lib/dictization/model_save.py b/ckan/lib/dictization/model_save.py
--- a/ckan/lib/dictization/model_save.py
+++ b/ckan/lib/dictization/model_save.py
@@ -27,7 +27,6 @@ def resource_dict_save(res_dict, context):
     table = class_mapper(model.Resource).mapped_table
     fields = [field.name for field in table.c]
 
-
     # Resource extras not submitted will be removed from the existing extras
     # dict
     new_extras = {}
@@ -40,7 +39,9 @@ def resource_dict_save(res_dict, context):
             if isinstance(getattr(obj, key), datetime.datetime):
                 if getattr(obj, key).isoformat() == value:
                     continue
-            if key == 'url' and not new and obj.url <> value:
+                if key == 'last_modified' and not new:
+                    obj.url_changed = True
+            if key == 'url' and not new and obj.url != value:
                 obj.url_changed = True
             setattr(obj, key, value)
         else:
diff --git a/ckan/lib/uploader.py b/ckan/lib/uploader.py
--- a/ckan/lib/uploader.py
+++ b/ckan/lib/uploader.py
@@ -173,6 +173,7 @@ def __init__(self, resource):
             self.filename = munge.munge_filename(self.filename)
             resource['url'] = self.filename
             resource['url_type'] = 'upload'
+            resource['last_modified'] = datetime.datetime.utcnow()
             self.upload_file = upload_field_storage.file
         elif self.clear:
             resource['url_type'] = ''


Test patch: