Azure / Azure/azure-sdk-for-python
[azure-core][bug] wrong content-type in headers of multipart request when there is no file to send
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
For typespec definition https://github.com/allenjzhang/typespec-e2e-demo/blob/75f5f9ad85acb4e46095058bd1033ba9fe9be0a3/todoApp/spec/main.tsp#L84, the property for file part is optional which means the payload for multipart may not contain file and azure-core shall still send it as multipart payload. However, current azure-core use `files` to judge whether the payload is for multipart which is not accurate. If files are empty, the content-type of `default_headers` is set to [application/x-www-form-urlencoded](https://github.com/Azure/azure-sdk-for-python/blob/cb0221a5510389127a9678a12a0e4f2ad0677e62/sdk/core/azure-core/azure/core/rest/_helpers.py#L112C44-L112C77) which is wrong.
https://github.com/Azure/azure-sdk-for-python/blob/cb0221a5510389127a9678a12a0e4f2ad0677e62/sdk/core/azure-core/azure/core/rest/_rest_py3.py#L114-L119
https://github.com/Azure/azure-sdk-for-python/blob/cb0221a5510389127a9678a12a0e4f2ad0677e62/sdk/core/azure-core/azure/core/rest/_rest_py3.py#L155-L158
Steps to repro:
1. clone `https://github.com/allenjzhang/typespec-e2e-demo.git`
2. step into the cloned repo and run `npm install`
3. annotate this [line](https://github.com/allenjzhang/typespec-e2e-demo/blob/b950c9d05a51aafee0bd54efa4ab2df5969ef062/todoApp/samples/python/sample.py#L44) then follow https://github.com/allenjzhang/typespec-e2e-demo/blob/main/todoApp/samples/python/README.md to run the sample and you can get error:

Contributor guide
Assessment
This issue has not been assessed yet.