Skip to content

Commit

Permalink
Merge pull request #8 from dataiku/fix/all-drive-support-on-create
Browse files Browse the repository at this point in the history
[sc-77983] Fix operations on shared folders
  • Loading branch information
alexbourret committed Jun 21, 2022
2 parents 1b86d62 + a785507 commit c988fec
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Version 1.1.3](https://github.com/dataiku/dss-plugin-googledrive/releases/tag/v1.1.3) - Fix release - 2022-01-05

- Fix issues with operating files within a shared drive

## [Version 1.1.2](https://github.com/dataiku/dss-plugin-googledrive/releases/tag/v1.1.2) - Fix release - 2021-09-20

- Fix issue with overwriting existing file
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2021 Dataiku
Copyright 2021-2022 Dataiku SAS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ This Dataiku DSS plugin provides a read / write connector to interact with docum
Documentation: https://www.dataiku.com/product/plugins/google-drive/

### Licence

Copyright 2021-2022 Dataiku SAS

This plugin is distributed under the Apache License version 2.0
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "googledrive",
"version": "1.1.2",
"version": "1.1.3",
"meta": {
"label": "Google Drive",
"description": "Read and write data from/to your Google Drive account",
Expand Down
30 changes: 20 additions & 10 deletions python-lib/dku_googledrive/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def googledrive_list(self, query):
except HttpError as err:
self.handle_googledrive_errors(err, "list")
attempts = attempts + 1
logger.info('googledrive_list:attempts={}'.format(attempts))
logger.info('googledrive_list:attempts={} on {}'.format(attempts, query))
raise GoogleDriveSessionError("Max number of attempts reached in Google Drive directory list operation")

def create_directory_from_path(self, path):
Expand Down Expand Up @@ -175,13 +175,14 @@ def googledrive_create(self, body, media_body=None, parent_id=None):
file = self.drive.files().create(
body=body,
media_body=media_body,
fields=gdu.ID
fields=gdu.ID,
supportsAllDrives=True
).execute()
return file
except HttpError as err:
self.handle_googledrive_errors(err, "create")
attempts = attempts + 1
logger.info('googledrive_create:attempts={}'.format(attempts))
logger.info('googledrive_create:attempts={} on {}'.format(attempts, body))
raise GoogleDriveSessionError("Max number of attempts reached in Google Drive directory create operation")

def googledrive_upload(self, filename, file_handle, parent_id=None):
Expand Down Expand Up @@ -230,13 +231,14 @@ def googledrive_update(self, file_id, body, media_body=None, parent_id=None):
fileId=file_id,
body=body,
media_body=media_body,
fields=gdu.ID
fields=gdu.ID,
supportsAllDrives=True
).execute()
logger.info("googledrive_update on {} successfull".format(file_id))
logger.info("googledrive_update on {} successfull".format(body))
return file
except HttpError as err:
if err.resp.status == 404:
logger.info("googledrive_update: 404 on {}, trying googledrive_create".format(file_id))
logger.info("googledrive_update: 404 on {}, trying googledrive_create".format(body))
file = self.googledrive_create(
body=body,
media_body=media_body,
Expand All @@ -247,23 +249,31 @@ def googledrive_update(self, file_id, body, media_body=None, parent_id=None):
else:
self.handle_googledrive_errors(err, "update")
attempts = attempts + 1
logger.info('googledrive_update:googledrive_create successful')
logger.info('googledrive_update:attempts={} on {}'.format(attempts, body))
raise GoogleDriveSessionError("Max number of attempts reached in Google Drive directory update operation")

def googledrive_delete(self, item, parent_id=None):
attempts = 0
while attempts < self.max_attempts:
try:
if len(item[gdu.PARENTS]) == 1 or parent_id is None:
self.drive.files().delete(fileId=gdu.get_id(item)).execute()
self.drive.files().delete(
fileId=gdu.get_id(item),
supportsAllDrives=True
).execute()
else:
self.drive.files().update(fileId=gdu.get_id(item), removeParents=parent_id).execute()
self.drive.files().update(
fileId=gdu.get_id(item),
removeParents=parent_id,
supportsAllDrives=True
).execute()
except HttpError as err:
logger.warn("HttpError={}".format(err))
if err.resp.status == 404:
return
self.handle_googledrive_errors(err, "delete")
attempts = attempts + 1
logger.info('googledrive_update:attempts={}'.format(attempts))
logger.info('googledrive_delete:attempts={} on {}'.format(attempts, item))
raise GoogleDriveSessionError("Max number of attempts reached in Google Drive directory delete operation")

def handle_googledrive_errors(self, err, context=""):
Expand Down

0 comments on commit c988fec

Please sign in to comment.