Skip to content

Send an empty JSON body for parameterless POST/PUT/PATCH requests - #1481

Closed
tejaskochar-db wants to merge 1 commit into
mainfrom
fix/json-body-on-parameterless-post
Closed

Send an empty JSON body for parameterless POST/PUT/PATCH requests#1481
tejaskochar-db wants to merge 1 commit into
mainfrom
fix/json-body-on-parameterless-post

Conversation

@tejaskochar-db

@tejaskochar-db tejaskochar-db commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Send an empty JSON object as the body for POST/PUT/PATCH requests that declare Content-Type: application/json but have no body to serialize, so the request is well-formed on the wire instead of being sent with no body at all.

Why

API methods for resource actions that take no parameters — for example WorkspaceClient.knowledge_assistants.sync_knowledge_sources(...), which issues POST .../knowledge-sources:sync — set Content-Type: application/json but pass no body to _BaseClient.do.

body defaults to None, and _perform calls requests with json=None. requests treats json=None as no body: the request goes out with Content-Length: 0 while still advertising Content-Type: application/json. Some Databricks API gateways require a JSON body (even an empty {}) for these endpoints and reject the bodyless request with 400 Bad Request.

The same operation succeeds when a body is supplied — calling w.api_client.do("POST", ".../knowledge-sources:sync", body={}) directly works. The proof is in how requests prepares the body:

call wire body Content-Length
json=None None 0
json={} b"{}" 2

This affects every generated method that declares a JSON content type but has no request fields (resource actions such as :sync, start, stop, cancel, undelete, …) — 20 such methods in the SDK today, and any added later.

What changed

Interface changes

None.

Behavioral changes

_BaseClient.do now defaults body to {} when all of the following hold: the method is POST/PUT/PATCH, Content-Type is application/json, and no body, data, or files is supplied. These requests previously went out with no body; they now carry {}.

GET/DELETE/HEAD, requests that already carry a body, and requests that do not declare application/json (e.g. streamed application/octet-stream uploads, or actions that intentionally send no body) are unchanged.

This mirrors the Go SDK, which marshals an empty request struct to {} and so has always sent a body for these endpoints.

Internal changes

None.

How is this tested?

Unit tests in tests/test_base_client.py cover the positive case parametrized over POST/PUT/PATCH (now sends {}) and the boundaries that must stay unchanged: a POST without a JSON content type sends no body; a GET is never given a body; an explicit files={} is left alone (no body injected); and an explicitly supplied falsy body such as [] is sent verbatim. Each test was confirmed to fail when the corresponding production logic is broken. Full test_base_client.py suite passes.


This pull request and its description were written by Isaac.

Generated methods for resource actions that take no parameters (for example
KnowledgeAssistantsAPI.sync_knowledge_sources, a POST to
".../knowledge-sources:sync") set Content-Type: application/json but pass no
body. requests serializes json=None as no request body at all, so these
requests advertise JSON yet send nothing on the wire, and some Databricks API
gateways reject them with a 400 BadRequest.

Default the body to an empty object in _BaseClient.do when a POST/PUT/PATCH
declares application/json and carries no body, data, or files, so the request
is well-formed. This matches the Go SDK, which marshals an empty request to
"{}". GET/DELETE/HEAD and requests that already carry a body are unaffected.

Co-authored-by: Isaac
@tejaskochar-db
tejaskochar-db force-pushed the fix/json-body-on-parameterless-post branch from c33b7c2 to 2becbe8 Compare June 23, 2026 10:41
@github-actions

Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-py

Inputs:

  • PR number: 1481
  • Commit SHA: 2becbe80fea3e05a98bf6e61281949e602944d20

Checks will be approved automatically on success.

@tejaskochar-db

Copy link
Copy Markdown
Contributor Author

Closing this manual draft. This change will be delivered through the regular automated SDK update instead.

@tejaskochar-db
tejaskochar-db deleted the fix/json-body-on-parameterless-post branch June 23, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant