Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/taskgraph/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ def get_taskcluster_client(service: str):
def _handle_artifact(
path: str, response: Union[requests.Response, dict[str, Any]]
) -> Any:
if isinstance(response, dict):
# When taskcluster client returns non-JSON responses, it wraps them in {"response": <Response>}
if "response" in response and isinstance(
response["response"], requests.Response
):
response = response["response"]
else:
# If we already a dict (parsed JSON), return it directly.
return response
# When taskcluster client returns non-JSON responses, it wraps them in {"response": <Response>}
if (
isinstance(response, dict)
and "response" in response
and isinstance(response["response"], requests.Response)
):
response = response["response"]

if not isinstance(response, requests.Response):
# At this point, if we don't have a response object, it's already parsed, return it
return response

# We have a response object, load the content based on the path extension.
if path.endswith(".json"):
Expand Down
11 changes: 11 additions & 0 deletions test/test_util_taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ def test_get_artifact(responses, root_url):
result = tc.get_artifact(tid, "artifact.json")
assert result == {"foo": "bar"}

# Test JSON artifact that isn't a dict (bug 1997236)
responses.get("http://foo.bar/artifact.json", json=[1, 2, 3])
responses.get(
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.json",
body=b'{"type": "s3", "url": "http://foo.bar/artifact.json"}',
status=303,
headers={"Location": "http://foo.bar/artifact.json"},
)
result = tc.get_artifact(tid, "artifact.json")
assert result == [1, 2, 3]

# Test YAML artifact
expected_result = {"foo": b"\xe2\x81\x83".decode()}
responses.get(
Expand Down
Loading