GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Explicitly set boundary for multipart/form-data by linkdd · Pull Request #1005 · openapi-generators/openapi-python-client

Conversation

@linkdd

@linkdd linkdd commented Mar 15, 2024

Copy link
Copy Markdown
Contributor
Python Version OpenAPI Client Generator Version
3.11.6 0.18.0

Actual Behavior

When an endpoint only has one body type, which is multipart/form-data, the Content-Type header is not set, so that HTTPX can set it with the correct boundary.

However, when an endpoint has multiple body types, the Content-Type header is always set, and HTTPX do not override it, which results in a missing boundary for multipart/form-data body types (resulting in a 400 - Bad Request response from the servers).

Proposed Changes

Let's always set the boundary to +++ to avoid any potential problem.

NB: This is kind of related to #1004, since in my specific case, the multipart/form-data body type is the last, it is always the one that is used.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fanshan, dzove855, Henri-J-Norden, Juno-T, and bartlomiejwiater reacted with thumbs up emoji
All reactions
  • 👍 5 reactions
linkdd and others added 3 commits March 15, 2024 15:40
@linkdd
Explicitly set boundary for multipart/form-data
c46d511
@dbanty
Merge branch 'main' into multipart-boundary
b1ca087
@dbanty
Merge branch 'main' into multipart-boundary
fb9d26e
@dbanty dbanty changed the title Explicitly set boundary for multipart/form-data fix: Explicitly set boundary for multipart/form-data May 30, 2026
dbanty and others added 2 commits May 30, 2026 10:48
@dbanty
Regen snapshots
df37219
@dbanty
Merge branch 'main' into multipart-boundary
19cc12d
@dbanty
dbanty force-pushed the multipart-boundary branch from e48dfc7 to 9c3f8b1 Compare May 30, 2026 16:58
@dbanty
Remove extra whitespace
cb36cbd
@dbanty
dbanty force-pushed the multipart-boundary branch from 9c3f8b1 to cb36cbd Compare May 30, 2026 16:59
@dbanty
Raise minimum httpx version to 0.23.1 to support explicit boundary
4bcd4d1
dbanty
dbanty approved these changes May 30, 2026
View reviewed changes
@dbanty
dbanty added this pull request to the merge queue May 30, 2026
Merged via the queue into openapi-generators:main with commit fb3f866 May 30, 2026
41 of 43 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@knope-bot knope-bot Bot mentioned this pull request May 30, 2026
Release 0.29.0 #1439
Merged
iloveitaly pushed a commit to iloveitaly/openapi-python-client that referenced this pull request May 31, 2026
@knope-bot
Release 0.29.0 (openapi-generators#1439)
7939364
> [!IMPORTANT]
> Merging this pull request will create this release

## Breaking Changes

- Drop support for Python 3.10
- Raise minimum httpx version to 0.23.1

## Features

- replace python-dateutil with stdlib datetime.fromisoformat (openapi-generators#1429)

## Fixes

- Remove some generated casts that aren't necessary with mypy v2 (openapi-generators#1436)
- Explicitly set boundary for multipart/form-data (openapi-generators#1005)

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
@alanwilter alanwilter mentioned this pull request Nov 5, 2026
Fixed multipart boundary "+++" (since 0.29.0) truncates uploads whose content contains \r\n--+++ #1509
Closed
@RClaudiuM RClaudiuM mentioned this pull request Nov 7, 2026
fix: Let httpx2 choose the multipart/form-data boundary #1511
Merged
sda-mikerochefort pushed a commit to sda-mikerochefort/openapi-python-client that referenced this pull request Nov 7, 2026
@RClaudiuM
fix: Let httpx2 choose the multipart/form-data boundary (openapi-gene…
4d6baa7
…rators#1511)

Fixes openapi-generators#1509

Since openapi-generators#1005 every generated `multipart/form-data` request sets
`Content-Type: multipart/form-data; boundary=+++`. httpx2 builds the
body with that boundary, so a file that contains `\r\n--+++` is split
there and the server gets a truncated file plus a stray part.

This stops setting `Content-Type` for `multipart/form-data` bodies.
httpx2 then adds the header with its own random boundary, the same way
single-body endpoints worked before 0.29.0. For endpoints with several
body types, the multipart branch no longer sets the header either, so
openapi-generators#947 stays fixed: httpx2 still writes a boundary because the header
isn't set. The other content types still set their header explicitly.

Changes:
- `endpoint_module.py.jinja`: skip the `Content-Type` line for multipart
bodies.
- Golden records and the integration-test client regenerated (only the
`boundary=+++` line goes away).
- New functional test `test_multipart_bodies.py`: generates a
single-body and a multi-body endpoint, sends a file containing
`\r\n--+++` through a `MockTransport` and parses the multipart body
back.
- Patch changeset.

Testing:
- `pytest
end_to_end_tests/functional_tests/generated_code_execution/test_multipart_bodies.py`
- before the template change: 2 failed (`{'file': b'first line'} !=
{'file': b'first line\r\n--+++\r\nstill the same file\r\n'}`), 1 passed
(JSON control)
  - after: 3 passed
- Full `pdm test` equivalent with coverage: 471 passed, 100% coverage, 5
snapshots passed
- `ruff format --check .`, `ruff check .`, `mypy openapi_python_client
fuzz` pass

I didn't run the `integration` job locally because it needs the
openapi-test-server container.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dbanty dbanty dbanty approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@linkdd @dbanty
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.