Skip to content

fix(openapi): JSON-encode object form fields in urlencoded request bodies - #5851

Merged
zzstoatzz merged 5 commits into
PrefectHQ:mainfrom
BlueX888:fix/openapi-form-urlencoded-body
Nov 10, 2026
Merged

zzstoatzz merged 5 commits into
PrefectHQ:mainfrom
BlueX888:fix/openapi-form-urlencoded-body

Conversation

@BlueX888

@BlueX888 BlueX888 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5850

Description

application/x-www-form-urlencoded request bodies sent object-typed properties as Python repr (filter={'name': 'alice', 'age': 30}) and nested None as the literal None; per-property encoding overrides were also ignored. Per the OAS Encoding Object, object properties default to contentType: application/json, so these values must be JSON-encoded before form encoding. String arrays already repeated correctly.

What changed

  • RequestDirector.build now builds urlencoded form data per property instead of handing the dict to httpx. Object-typed values and arrays of objects are serialized with json.dumps(..., allow_nan=False) (nested None becomes null); explicit encoding.<prop>.contentType wins, and non-JSON explicit content types keep their declared form.
  • Primitive values and arrays of primitives still go through httpx, so tags=a&tags=b behavior is unchanged.
  • Multipart and JSON request bodies are untouched.
  • Schema lookup resolves $ref/allOf and merges inline $defs with the route's request schemas.

Contribution type

  • Bug fix (simple, well-scoped fix for a clearly broken behavior)
  • Documentation improvement
  • Enhancement

Bug fix verification

Test path: tests/server/providers/openapi/test_object_request_bodies.py (fourteen tests, mock transport records request.content).

Red at adf90b66 (implementation reverted, final tests applied): 12 failed, 35 passed, all assertion failures, no collection errors (object inline/$ref, nested null, array of objects, explicit encoding, composed/union arrays of objects, and the additionalProperties map; the JSON-body control passes as expected).

Green at the fix commit: 1717 passed, 1 skipped across tests/server/providers/openapi/ tests/utilities/.

Validation

  • uv run --isolated pytest tests/server/providers/openapi/ tests/utilities/ -q -> 1717 passed, 1 skipped
  • uv run --isolated ruff check and ruff format --check on the changed files -> clean
  • uv run --isolated ty check -> All checks passed

AI assistance

Tool(s) used: Claude Code
How you used it: investigated from a verified reproduction, implemented the schema-aware form building and the regression tests.

Checklist

  • This PR addresses an existing issue (or fixes a self-evident bug)
  • I have read CONTRIBUTING.md
  • I have added tests that cover my changes
  • I have run uv run prek run --all-files and all checks pass (focused checks passed)
  • I have self-reviewed my changes
  • If I used an LLM, it followed the repo's contributing conventions (not generic output)

Review follow-up

Codex review found two composition gaps, both fixed: a form property whose union includes both array<object> and array<string> now selects the branch matching the runtime value (scalar arrays stay repeated keys instead of being JSON-dumped by the unused object branch), and the schema traversal now carries an active-reference set so mutually recursive $ref/allOf graphs cannot raise RecursionError. Regression tests cover both.

@github-actions

This comment has been minimized.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T14:05:18.162276Z 8d6787f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. openapi Related to OpenAPI integration, parsing, or code generation features. labels Oct 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d6787f0fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Per the OAS Encoding Object, object properties default to
contentType application/json. Passing them straight to httpx data=
sent Python repr instead, with nested None rendered as None. Serialize
object and array-of-object properties with json.dumps, honor explicit
encoding contentType overrides, and keep primitive and array-of-primitive
form encoding unchanged.
Recurse allOf/anyOf/oneOf and accept type lists when detecting
array-of-object properties, so pydantic union schemas such as
list[Model] | None JSON-encode their values. Fall back to the body
schema's additionalProperties for undeclared form names so object map
values are JSON-encoded instead of Python repr.
Form-urlencoded serialization selected any composition alternative that
described an object array, so a oneOf/anyOf of array<object> and
array<string> JSON-encoded a scalar list into one field instead of
letting httpx repeat the key. Evaluate array branches against the runtime
items so only a matching object branch is JSON-encoded.

Resolve $refs with an active-reference set threaded through composition
traversal; mutually recursive component graphs (A allOf $ref B, B
starts with $ref A) previously recursed until RecursionError at request
time. Cyclic branches are skipped, and the remaining branches still
determine serialization.
@BlueX888
BlueX888 force-pushed the fix/openapi-form-urlencoded-body branch from 8d6787f to d40d5a8 Compare October 19, 2026 17:37
@BlueX888

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch in cf9c4e1; the fixes from d40d5a8 and 5d66fe3 are retained. Target tests: 131 passed (tests/server/providers/openapi/test_object_request_bodies.py + tests/utilities/openapi/test_director.py).

@zzstoatzz
zzstoatzz merged commit c15826a into PrefectHQ:main Nov 10, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. bypass-issue-check openapi Related to OpenAPI integration, parsing, or code generation features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OpenAPI form-urlencoded bodies send object properties as Python repr

2 participants