Skip to content

Commit bec60d2

Browse files
authored
Merge pull request #70 from dataiku/bug/sc-236608-length-of-the-url-for-long-paths
fix: [sc-236608] Fix The length of the URL for this request exceeds the configured maxUrlLength value by trying to use URL parameters
2 parents 0f4b553 + 5ee46a1 commit bec60d2

File tree

4 files changed

+78
-30
lines changed

4 files changed

+78
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [Version 1.1.6](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.1.6) - Bugfix release - 2025-04-01
4+
5+
- Fix issue with 255+ chars file paths. The new limit is 400 chars, imposed by SharePoint's API.
6+
37
## [Version 1.1.5](https://github.com/dataiku/dss-plugin-sharepoint-online/releases/tag/v1.1.5) - Bugfix release - 2024-12-04
48

59
- Reduce log verbosity around retry functions

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "sharepoint-online",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"meta": {
55
"label": "SharePoint Online",
66
"description": "Read and write data from/to your SharePoint Online account",

python-lib/dss_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DSSConstants(object):
3737
"sharepoint_oauth": "The access token is missing"
3838
}
3939
PATH = 'path'
40-
PLUGIN_VERSION = "1.1.5"
40+
PLUGIN_VERSION = "1.1.6"
4141
SECRET_PARAMETERS_KEYS = ["Authorization", "sharepoint_username", "sharepoint_password", "client_secret", "client_certificate", "passphrase"]
4242
SITE_APP_DETAILS = {
4343
"sharepoint_tenant": "The tenant name is missing",

python-lib/sharepoint_client.py

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,28 +186,47 @@ def setup_sharepoint_online_url(self, login_details):
186186
)
187187

188188
def get_folders(self, path):
189-
response = self.session.get(self.get_folder_url(path) + "/Folders")
189+
url = self.get_folder_url() + "/Folders/{}".format(
190+
self.get_path_as_query_string(path)
191+
)
192+
response = self.session.get(url)
190193
self.assert_response_ok(response, calling_method="get_folders")
191194
return response.json()
192195

193196
def get_files(self, path):
194-
response = self.session.get(self.get_folder_url(path) + "/Files")
197+
response = self.session.get(self.get_folder_url() + "/Files/{}".format(
198+
self.get_path_as_query_string(path)
199+
)
200+
)
195201
self.assert_response_ok(response, calling_method="get_files")
196202
return response.json()
197203

198204
def get_item_fields(self, path):
199-
response = self.session.get(self.get_folder_url(path) + "/ListItemAllFields")
205+
response = self.session.get(self.get_folder_url() + "/ListItemAllFields{}".format(
206+
self.get_path_as_query_string(path)
207+
))
200208
self.assert_response_ok(response, calling_method="get_item_fields")
201209
return response.json()
202210

203211
def get_start_upload_url(self, path, upload_id):
204-
return self.get_file_url(path) + "/startupload(uploadId=guid'{}')".format(upload_id)
212+
return self.get_file_url() + "/startupload(uploadId=guid'{}'){}".format(
213+
upload_id,
214+
self.get_path_as_query_string(path)
215+
)
205216

206217
def get_continue_upload_url(self, path, upload_id, file_offset):
207-
return self.get_file_url(path) + "/continueupload(uploadId=guid'{}',fileOffset={})".format(upload_id, file_offset)
218+
return self.get_file_url() + "/continueupload(uploadId=guid'{}',fileOffset={}){}".format(
219+
upload_id,
220+
file_offset,
221+
self.get_path_as_query_string(path)
222+
)
208223

209224
def get_finish_upload_url(self, path, upload_id, file_offset):
210-
return self.get_file_url(path) + "/finishupload(uploadId=guid'{}',fileOffset={})".format(upload_id, file_offset)
225+
return self.get_file_url() + "/finishupload(uploadId=guid'{}',fileOffset={}){}".format(
226+
upload_id,
227+
file_offset,
228+
self.get_path_as_query_string(path)
229+
)
211230

212231
def is_file(self, path):
213232
item_fields = self.get_item_fields(path)
@@ -704,59 +723,76 @@ def get_guid_lists_add_field_url(self, list_id):
704723
list_id
705724
)
706725

707-
def get_folder_url(self, full_path):
708-
if full_path == '/':
709-
full_path = ""
710-
return self.get_base_url() + "/GetFolderByServerRelativePath(decodedurl='{}')".format(
711-
url_encode(self.get_site_path(full_path))
712-
)
726+
def get_folder_url(self, full_path=None):
727+
if full_path:
728+
if full_path == '/':
729+
full_path = ""
730+
return self.get_base_url() + "/GetFolderByServerRelativePath(decodedurl='{}')".format(
731+
url_encode(self.get_site_path(full_path))
732+
)
733+
else:
734+
return self.get_base_url() + "/GetFolderByServerRelativePath(decodedurl=@a1)"
713735

714-
def get_file_url(self, full_path):
715-
return self.get_base_url() + "/GetFileByServerRelativePath(decodedurl='{}')".format(
716-
url_encode(self.get_site_path(full_path))
717-
)
736+
def get_file_url(self, full_path=None):
737+
if full_path:
738+
return self.get_base_url() + "/GetFileByServerRelativePath(decodedurl='{}')".format(
739+
url_encode(self.get_site_path(full_path))
740+
)
741+
else:
742+
return self.get_base_url() + "/GetFileByServerRelativePath(decodedurl=@a1)"
718743

719744
def get_file_content_url(self, full_path):
720-
return self.get_file_url(full_path) + "/$value"
745+
return self.get_file_url() + "/$value{}".format(
746+
self.get_path_as_query_string(full_path)
747+
)
721748

722749
def get_move_url(self, from_path, to_path):
723750
# Using the new method leads to 403.
724751
# Old method left in place. As a result, moving/renaming a file containing % in its path/name is still not possible.
725752
# return self.get_file_url(from_path) + "/movetousingpath(newPath='{}',moveOperations=1)".format(
726-
return self.get_file_url(from_path) + "/moveto(newurl='{}',flags=1)".format(
753+
return self.get_file_url() + "/moveto(newurl=@a2,flags=1)?@a1='{}'&@a2='{}'".format(
754+
url_encode(self.get_site_path(from_path)),
727755
url_encode(self.get_site_path(to_path))
728756
)
729757

730758
def get_recycle_file_url(self, full_path):
731-
return self.get_file_url(full_path) + "/recycle()"
759+
return self.get_file_url() + "/recycle(){}".format(
760+
self.get_path_as_query_string(full_path)
761+
)
732762

733763
def get_recycle_folder_url(self, full_path):
734-
return self.get_folder_url(full_path) + "/recycle()"
764+
return self.get_folder_url() + "/recycle(){}".format(
765+
self.get_path_as_query_string(full_path)
766+
)
735767

736768
def get_file_check_in_url(self, full_path):
737-
return self.get_file_url(full_path) + "/CheckIn()"
769+
return self.get_file_url() + "/CheckIn(){}".format(
770+
self.get_path_as_query_string(full_path)
771+
)
738772

739773
def get_file_check_out_url(self, full_path):
740-
return self.get_file_url(full_path) + "/CheckOut()"
774+
return self.get_file_url() + "/CheckOut(){}".format(
775+
self.get_path_as_query_string(full_path)
776+
)
741777

742778
def get_site_path(self, full_path):
743779
return "/{}/{}{}".format(
744780
self.escape_path(self.sharepoint_site),
745781
self.escape_path(self.sharepoint_root),
746782
self.escape_path(full_path)
747-
)
783+
).replace("//", "/")
748784

749785
def get_add_folder_url(self, full_path):
750-
path = merge_paths(self.sharepoint_root, full_path)
751-
return self.get_base_url() + "/Folders/AddUsingPath(decodedurl='{}')".format(
752-
url_encode(path)
786+
return self.get_base_url() + "/Folders/AddUsingPath(decodedurl=@a1){}".format(
787+
self.get_path_as_query_string(full_path)
753788
)
754789

755790
def get_file_add_url(self, full_path, file_name):
756-
return self.get_folder_url(full_path) + "/Files/AddUsingPath(decodedurl='{}',overwrite=true)".format(
791+
return self.get_folder_url() + "/Files/AddUsingPath(decodedurl='{}',overwrite=true){}".format(
757792
url_encode(
758793
self.escape_path(file_name)
759-
)
794+
),
795+
self.get_path_as_query_string(full_path)
760796
)
761797

762798
def get_list_default_view_url(self, list_title):
@@ -765,6 +801,14 @@ def get_list_default_view_url(self, list_title):
765801
SharePointConstants.DEFAULT_VIEW_ENDPOINT
766802
)
767803

804+
def get_path_as_query_string(self, path):
805+
if path:
806+
if path == '/':
807+
path = ""
808+
return "?@a1='{}'".format(
809+
url_encode(self.get_site_path(path))
810+
)
811+
768812
@staticmethod
769813
def assert_login_details(required_keys, login_details):
770814
if login_details is None or login_details == {}:

0 commit comments

Comments
 (0)