Azure / Azure/azure-sdk-for-python

[azure-core][bug] wrong content-type in headers of multipart request when there is no file to send

Open
#39,163 1 comment 0 reactions 0 assignees View on GitHub
Azure.Core bug Client
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:

![Image](https://github.com/user-attachments/assets/2adcc1a3-6919-40b6-8e44-fc1046c6f9f6)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.