Problem with setting of SP file modification date (preserving it through update of custom property)
Hello. My goal is to preserve modification time after value is assigned to a custom property of SharePoint file (unfortunately it changes modification time, what is not desired). I did follow example from ticket. The query did not return exception. Actually I got positive response (if time format was wrong I was getting item.HasException == True), but still it did not influence 'Modified:' property correctly. Actually, file modification time was updated to the time of when this request was sent!
This is the code I've written:
def mark_processed(self, file):
'''Set property of SharePoint file indicating that it was processed'''
file_id = file.listItemAllFields.get().execute_query().id
file_item = self.ctx.web.lists.get_by_title(self.sharepoint_lib).get_item_by_id(file_id).get().execute_query()
file_metadata = file_item.properties
property_name = self.processed_poperty_name()
if not property_name in file_metadata.keys():
self.create_property(property_name)
now_str = datetime.today().strftime(SP_DATE_WRITE_FORMAT)
mdate_utc = datetime.strptime(file_metadata['Modified'], SP_DATE_READ_FORMAT)
mdate_str = mdate_utc.replace(tzinfo=tz.utc).astimezone().strftime(SP_DATE_WRITE_FORMAT)
client_result = file_item.validate_update_list_item(
{
property_name: now_str,
'Modified': mdate_str # Does not work
}
).execute_query()
self.raise_for_o365(client_result)
logger.debug('Set property %s of %s as %s', property_name, file.serverRelativeUrl , now_str)
def raise_for_o365(self, result):
'''Raise exception if o365 request finished with exception'''
for item in result.value:
if item.HasException:
raise requests.RequestException(f'SharePoint API resulted with error: {item.ErrorMessage}')
This is intended behavior. You are modifying a property of a listItem hence the modification time is changed.
If you were working with a Document Library, then modification time would only reflect the file itself.
@dkuska - thanks for responding, I do work with Document Library. Does it have differently in case of Tasks library? @vgrem provided code here ((https://github.com/vgrem/Office365-REST-Python-Client/issues/330)) which according to him does preserve modification time.