Skip to content

Use requests' json argument when passing JSON to the taskcluster API#415

Merged
tomrittervg merged 1 commit into
mozilla-services:masterfrom
Eijebong:json-tc
May 20, 2026
Merged

Use requests' json argument when passing JSON to the taskcluster API#415
tomrittervg merged 1 commit into
mozilla-services:masterfrom
Eijebong:json-tc

Conversation

@Eijebong

Copy link
Copy Markdown
Contributor

When triggering hooks, the previous code was serializing the JSON itself then passing it straight to taskcluster as a string with no content type. This currently works because the taskcluster proxy has a workaround (see taskcluster/taskcluster#3521) that sets the content type to application/json if it's missing from a request with a non empty body. This means that if that workaround was ever removed or if this script tries to target taskcluster directly without the proxy, the request would fail. Just use requests.post(json= and get serialization and the header for free.

The manual json.dumps() and the \n to space replace were leftovers from when the payload was shelled out through echo -n '...' | taskcluster-darwin-amd64 in the past, where embedded newlines broke the quoted shell string.

When triggering hooks, the previous code was serializing the JSON itself
then passing it straight to taskcluster as a string with no content
type. This currently works because the taskcluster proxy has a
workaround (see taskcluster/taskcluster#3521)
that sets the content type to application/json if it's missing from a
request with a non empty body. This means that if that workaround was
ever removed or if this script tries to target taskcluster directly
without the proxy, the request would fail. Just use
`requests.post(json=` and get serialization and the header for free.

The manual json.dumps() and the \n to space replace were leftovers from
when the payload was shelled out through `echo -n '...' |
taskcluster-darwin-amd64` in the past, where embedded newlines broke the
quoted shell string.
Eijebong added a commit to Eijebong/taskcluster that referenced this pull request Apr 22, 2026
This removes a years old workaround for misbehaving clients. The
workaround was added in ef7164f (taskcluster#3671) to restore some behavior that
was accidentally dropped in f3c2473 when the proxy got put in the
monorepo. Before that move, the proxy was delegating outgoing requests
to `tcclient.Client.Request` which was unconditionally setting
`Content-Type` for any non-empty body. The monorepo version is calling
`http.NewRequest` directly which does not have that kind of behavior (so
the header disappeared).

I think it's time to let this debt go and do what was decided in taskcluster#3521, which
is to not touch headers in the proxy. I think it makes no sense to try
and fix a buggy client by hiding its behavior since it might also be run
directly talking to taskcluster and not through the proxy.

Worth noting, I checked papertrail for that log line and found one
offending client for which I opened a PR
(mozilla-services/updatebot#415).

Closes taskcluster#3521
Eijebong added a commit to Eijebong/taskcluster that referenced this pull request Apr 22, 2026
This removes a years old workaround for misbehaving clients. The
workaround was added in ef7164f (taskcluster#3671) to restore some behavior that
was accidentally dropped in f3c2473 when the proxy got put in the
monorepo. Before that move, the proxy was delegating outgoing requests
to `tcclient.Client.Request` which was unconditionally setting
`Content-Type` for any non-empty body. The monorepo version is calling
`http.NewRequest` directly which does not have that kind of behavior (so
the header disappeared).

I think it's time to let this debt go and do what was decided in taskcluster#3521, which
is to not touch headers in the proxy. I think it makes no sense to try
and fix a buggy client by hiding its behavior since it might also be run
directly talking to taskcluster and not through the proxy.

Worth noting, I checked papertrail for that log line and found one
offending client for which I opened a PR
(mozilla-services/updatebot#415).

Closes taskcluster#3521
@JohanLorenzo

Copy link
Copy Markdown

@tomrittervg hi 👋 Would you have some spare cycle to look at this PR? The taskcluster-proxy will soon be upgraded to the Firefox CI instance and will break without this PR.

@tomrittervg tomrittervg self-requested a review May 20, 2026 15:17
@tomrittervg tomrittervg merged commit 73a27db into mozilla-services:master May 20, 2026
16 checks passed
@tomrittervg

Copy link
Copy Markdown
Collaborator

Sorry for the delay

https://phabricator.services.mozilla.com/D301552

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.

3 participants