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: Let httpx2 choose the multipart/form-data boundary by RClaudiuM · Pull Request #1511 · openapi-generators/openapi-python-client

Conversation

@RClaudiuM

@RClaudiuM RClaudiuM commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #1509

Since #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 #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.

Sorry, something went wrong.

Uh oh!

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

All reactions
@RClaudiuM
fix: Let httpx2 choose the multipart/form-data boundary
3711503
Generated endpoints set Content-Type to multipart/form-data with the
fixed boundary +++, so a file containing "\r\n--+++" was split at that
point. Leave Content-Type unset for multipart bodies and let httpx2 add
it with a random boundary, which also covers endpoints with several
body types (openapi-generators#947).

Fixes openapi-generators#1509
dbanty
dbanty approved these changes Nov 7, 2026
View reviewed changes

@dbanty dbanty left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Sorry, something went wrong.

Uh oh!

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

All reactions
@dbanty
dbanty added this pull request to the merge queue Nov 7, 2026
Merged via the queue into openapi-generators:main with commit 4d6baa7 Nov 7, 2026
23 checks passed

Uh oh!

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

@knope-bot knope-bot Bot mentioned this pull request Nov 7, 2026
Release 0.30.0 #1510
Merged
sda-mikerochefort pushed a commit to sda-mikerochefort/openapi-python-client that referenced this pull request Nov 7, 2026
@knope-bot
Release 0.30.0 (openapi-generators#1510)
46a4340
> [!IMPORTANT]
> Merging this pull request will create this release

## ❗️Breaking ❗

### Switch from `httpx` to `httpx2` in generated clients

[`httpx2`](https://pydantic.dev/docs/httpx2/get-started/) is largely
compatible with `httpx` and should only be a breaking change for users
who customize the internal `Client`.

Thanks to @s-sajid-ali and @johnthagen for making this one happen in PR
openapi-generators#1461 and discussion openapi-generators#1455!

## 🚀 Features

- Update `uv_build` to 0.13 when using `--meta=uv` (openapi-generators#1507)

## 🐛 Fixes

- Let httpx2 choose the multipart/form-data boundary (openapi-generators#1511)

### Let httpx2 choose the boundary for `multipart/form-data` requests

Since 0.29.0, generated endpoints sent every `multipart/form-data` body
with the fixed boundary `+++`, so an uploaded file containing
`\r\n--+++` was cut short at that point (openapi-generators#1509). These bodies no longer
set `Content-Type`, so httpx2 sets it with a random boundary for each
request, as single-body endpoints did before 0.29.0. Endpoints with
several body types still get a boundary (openapi-generators#947).

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
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.

Fixed multipart boundary "+++" (since 0.29.0) truncates uploads whose content contains \r\n--+++

Uh oh!

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

2 participants

@RClaudiuM @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 01402520 — 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.