Skip to content

Problem with setting of SP file modification date (preserving it through update of custom property) #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
r2oro opened this issue Jul 20, 2023 · 2 comments
Labels

Comments

@r2oro
Copy link

r2oro commented Jul 20, 2023

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}')
@r2oro r2oro changed the title Problem with setting of SP ile modification date (preserving it after of custom property) Problem with setting of SP file modification date (preserving it after update of custom property) Jul 20, 2023
@r2oro r2oro changed the title Problem with setting of SP file modification date (preserving it after update of custom property) Problem with setting of SP file modification date (preserving it through update of custom property) Jul 20, 2023
@dkuska
Copy link

dkuska commented Jul 24, 2023

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.

@r2oro
Copy link
Author

r2oro commented Aug 8, 2023

@dkuska - thanks for responding, I do work with Document Library. Does it have differently in case of Tasks library? @vgrem provided code here ((#330)) which according to him does preserve modification time.

@vgrem vgrem added the question label Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants