Skip to content
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

GraphClient bug?: upload_file makes DriveItem unusable. #866

Closed
dekiesel opened this issue May 23, 2024 · 2 comments
Closed

GraphClient bug?: upload_file makes DriveItem unusable. #866

dekiesel opened this issue May 23, 2024 · 2 comments
Labels

Comments

@dekiesel
Copy link

dekiesel commented May 23, 2024

I have a DriveItem called drive. It is not the root of the drive, in case that matters.

It works as expected until I call upload_file on it.

Example

Immediately before calling upload_file calling drive.resource_path shows

/sites/mysite.sharepoint.com,ba872102-39d8-47ab-8aad-7d14db214a60,e28ca39c-5ac9-4639-9b54-7966cd9c088b/drive/items/01VUQUP4U66UKKQJ3QBJFYGNG4F22PKWZD

After calling upload_file:

/sites/mysite.sharepoint.com,ba872102-39d8-47ab-8aad-7d14db214a60,e28ca39c-5ac9-4639-9b54-7966cd9c088b/drive/items/b!AiGIgtg5q0eKrX0U2yFKYJyjjOHJWjlGm1R5Zs2cCIuSidtNh8SpSaOd3tUKggsG

Notice the exclamation mark.

From this point on I can't use drive anymore:

drive.children.get().execute_query()
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/office365/runtime/client_request.py", line 38, in execute_query
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com,ba872102-39d8-47ab-8aad-7d14db214a60,e28ca39c-5ac9-4639-9b54-7966cd9c088b/drive/items/b!AiGIutg5q0eKrX0U2yFKYJyjjOHJWjlGm1R5Zs2cCIuSidtNh8SpSaOd3tUKggsG/children

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/office365/runtime/client_object.py", line 53, in execute_query
    self.context.execute_query()
  File "/usr/local/lib/python3.12/site-packages/office365/runtime/client_runtime_context.py", line 173, in execute_query
    self.pending_request().execute_query(qry)
  File "/usr/local/lib/python3.12/site-packages/office365/runtime/client_request.py", line 42, in execute_query
    raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('invalidRequest', 'Invalid request', '400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com,ba872102-39d8-47ab-8aad-7d14db214a60,e28ca39c-5ac9-4639-9b54-7966cd9c088b/drive/items/b!AiGIutg5q0eKrX0U2yFKYJyjjOHJWjlGm1R5Zs2cCIuSidtNh8SpSaOd3tUKggsG/children')

This is how I call upload_file:
drive.upload_file(full_filepath).execute_query()

full_filepath is a string to a local file and the file is uploaded correctly.

Am I using it wrong or is this a bug?

Version:
Office365-REST-Python-Client==2.5.

Thanks!

@dekiesel
Copy link
Author

dekiesel commented May 24, 2024

I created two minimal (non-) working examples for this issue:

This works as expected:

    client = GraphClient.with_certificate(
        azure_tenant,
        client_id=sharepoint_access_app_id,
        thumbprint=sharepoint_certificate_thumbprint,
        private_key=str(certs[0]),
    )
    sites = client.sites.get().execute_query()
    site = [site for site in sites if site.name == mysite][0]
    drive = site.drive.execute_query()
    drive.root.upload_file(f"{local_root}/file0")
    drive.root.children.get().execute_query()

This does not work:

    client = GraphClient.with_certificate(
        azure_tenant,
        client_id=sharepoint_access_app_id,
        thumbprint=sharepoint_certificate_thumbprint,
        private_key=str(certs[0]),
    )
    sites = client.sites.get().execute_query()
    site = [site for site in sites if site.name == mysite][0]
    drive = site.drive.execute_query()
    drive = drive.root.create_folder("testfolder").execute_query()
    drive.upload_file(f"{local_root}/file0").execute_query()
    drive.children.get().execute_query()

Note the create_folder call.

('invalidRequest', 'Invalid request', '400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com,3f11ac12-bf77-4e3f-a76e-629796469238,803641c9-7da7-49d8-8044-0a166dbcc613/drive/items/b!EqwQP3e_P06nbmKXlkaSONlBNoCofdhJgEQKFm28xgL3QuuzSJs7TpTGFkF_Q5hc/children')
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com,3f11ac12-bf77-4e3f-a76e-629796469238,803641c9-7da7-49d8-8044-0a166dbcc613/drive/items/b!EqwQP3e_P06nbmKXlkaSONlBNoCofdhJgEQKFm28xgL3QuuzSJs7TpTGFkF_Q5hc/children

During handling of the above exception, another exception occurred:

  File "/workspaces/corelib_insource_investmentfiles/corelib_insource_investmentfiles/sharepoint_handler/sharepoint_handlerdebug.py", line 298, in <module>
    drive.children.get().execute_query()
office365.runtime.client_request_exception.ClientRequestException: ('invalidRequest', 'Invalid request', '400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com,3f11ac12-bf77-4e3f-a76e-629796469238,803641c9-7da7-49d8-8044-0a166dbcc613/drive/items/b!EqwQP3e_P06nbmKXlkaSONlBNoCofdhJgEQKFm28xgL3QuuzSJs7TpTGFkF_Q5hc/children')

My understanding is that this should work (which might be wrong).

@vgrem vgrem added the bug label May 26, 2024
vgrem added a commit that referenced this issue May 26, 2024
vgrem added a commit that referenced this issue May 26, 2024
@vgrem
Copy link
Owner

vgrem commented May 26, 2024

Greetings,

thank you for reporting this issue and providing the detailed analysis!
This bug (namely, drive item path gets incorrectly resolved when calling specific methods) has been addressed in a new 2.5.10 version.

@vgrem vgrem closed this as completed May 26, 2024
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

2 participants