Azure / Azure/azure-sdk-for-python
[azure-core][bug] wrong content-type in headers of multipart request when there is no file to send
- Vorherrschende Sprache
- Python
- Sterne
- 5.6k
- Forks
- 3.4k
- Ø Merge
- 2 T. 2 Std.
- Gemergte PRs (30 T.)
- 213
Beschreibung
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:

Beitragsleitfaden
Rechercherichtung
Beginnen Sie in azure/core/rest/_helpers.py und azure/core/rest/_rest_py3.py an den referenzierten Zeilen und reproduzieren Sie dann das Problem mit dem Python-Beispiel typespec-e2e-demo, nachdem Sie die angegebene Zeile annotiert haben. Verfolgen Sie, wie sich ein optionaler leerer Dateiteil auf die Anfrageklassifizierung und die Header auswirkt. Erledigt ist die Aufgabe, wenn die Anfrage als multipart gesendet wird, sobald der multipart-Payload keine Datei enthält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- azure, python
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100