iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
570 stars 70 forks source link

#223 silently renames file on update by ID #272

Closed gu-5000 closed 1 year ago

gu-5000 commented 1 year ago

I don't know if this issue counts as a bug, but at least in my case it breaks file updates and I had to search a lot to figure out what was going on.

With v1.15.1, when I update a file using only its ID (like below), the file is silently renamed from file.txt to /path/to/file.txt.

conf = {
    'id': file_id,
    'mimeType': 'application/zip',
    'parents':[{
        'kind': 'drive#fileLink', 
        'id': parent_id
    }]
}

gf = self.gdrive.CreateFile(conf)
gf.SetContentFile('/path/to/file.txt') 
gf.Upload()

This does not happen when using v1.14.0. I think it is a side effect of #223 and caused by the following in def SetContentFile(self, filename):

if self.get("title") is None:
    self["title"] = filename

A simple solution is of course to set the file name explicitly.