Send an empty JSON body for parameterless POST/PUT/PATCH requests - #1481
Closed
tejaskochar-db wants to merge 1 commit into
Closed
Send an empty JSON body for parameterless POST/PUT/PATCH requests#1481tejaskochar-db wants to merge 1 commit into
tejaskochar-db wants to merge 1 commit into
Conversation
tejaskochar-db
temporarily deployed
to
test-trigger-is
June 23, 2026 10:15 — with
GitHub Actions
Inactive
tejaskochar-db
temporarily deployed
to
test-trigger-is
June 23, 2026 10:15 — with
GitHub Actions
Inactive
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
force-pushed
the
fix/json-body-on-parameterless-post
branch
from
June 23, 2026 10:41
c33b7c2 to
2becbe8
Compare
tejaskochar-db
temporarily deployed
to
test-trigger-is
June 23, 2026 10:41 — with
GitHub Actions
Inactive
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
tejaskochar-db
temporarily deployed
to
test-trigger-is
June 23, 2026 10:42 — with
GitHub Actions
Inactive
Contributor
Author
|
Closing this manual draft. This change will be delivered through the regular automated SDK update instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Send an empty JSON object as the body for
POST/PUT/PATCHrequests that declareContent-Type: application/jsonbut 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 issuesPOST .../knowledge-sources:sync— setContent-Type: application/jsonbut pass nobodyto_BaseClient.do.bodydefaults toNone, and_performcallsrequestswithjson=None.requeststreatsjson=Noneas no body: the request goes out withContent-Length: 0while still advertisingContent-Type: application/json. Some Databricks API gateways require a JSON body (even an empty{}) for these endpoints and reject the bodyless request with400 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 howrequestsprepares the body:json=NoneNonejson={}b"{}"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.donow defaultsbodyto{}when all of the following hold: the method isPOST/PUT/PATCH,Content-Typeisapplication/json, and nobody,data, orfilesis 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 declareapplication/json(e.g. streamedapplication/octet-streamuploads, 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.pycover the positive case parametrized overPOST/PUT/PATCH(now sends{}) and the boundaries that must stay unchanged: aPOSTwithout a JSON content type sends no body; aGETis never given a body; an explicitfiles={}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. Fulltest_base_client.pysuite passes.This pull request and its description were written by Isaac.