microsoftgraph / microsoftgraph/msgraph-sdk-python

Setting additional_data for DriveItemUploadableProperties throw 400

Open
#949 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:uploads type:bug
Dominant language
Python
Stars
630
Forks
96
Avg merge
15h 20m
Merged PRs (30d)
3

Description

Describe the bug

When try to add any field from the docs, such as "description" or "@microsoft.graph.conflictBehavior" to DriveItemUploadableProperties from msgraph.generated.models.drive_item_uploadable_properties msgraph throw this:

E           msgraph.generated.models.o_data_errors.o_data_error.ODataError: 
E                   APIError
E                   Code: 400
E                   message: None
E                   error: MainError(additional_data={}, code='invalidRequest', details=None, inner_error=InnerError(additional_data={}, client_request_id='463c4945-0f9c-435e-9ece-30e48ff358b6', date=DateTime(2024, 11, 6, 8, 37, 41, tzinfo=Timezone('UTC')), odata_type=None, request_id='48083d5b-ecd3-4176-8447-112ab2233e72'), message='The request is malformed or incorrect.', target=None)

code i used for this:

        sp_url = f'{self.drive_path}/items/root:{remote_path}:'
        sp_session_url = sp_url + '/createUploadSession'

        base_request_builder = (
            self.client.drives.by_drive_id(self.drive_id)
            .items.by_drive_item_id("root").create_upload_session.with_url(
                sp_session_url,
            )
        )
        create_session_response = await base_request_builder.post(
            CreateUploadSessionPostRequestBody(
                item=DriveItemUploadableProperties(
                    name=file_name,
                    additional_data={
                        "@microsoft.graph.conflictBehavior": "rename",
                    },
                ),
            )
        )

I also tried to add additional_data to CreateUploadSessionPostRequestBody but it does nothing

Expected behavior

When uploading file to Sharepoint and file with the same name already exists it must add suffix (1) or _1 to the new file

How to reproduce

try to upload file with createUploadSession if file with that name already exists using code above

SDK Version

1.9.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the create_upload_session entry point and inspect how DriveItemUploadableProperties and CreateUploadSessionPostRequestBody serialize additional_data. Reproduce the request from the issue with msgraph.generated.models.drive_item_uploadable_properties and the @microsoft.graph.conflictBehavior field. Done means createUploadSession accepts the documented field and applies the requested conflict behavior when a file already exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.