Skip to content

Commit f374adc

Browse files
committed
fix: regression to artifact handling in util/taskcluster.py
1 parent da823c8 commit f374adc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import copy
77
import datetime
88
import functools
9+
import io
910
import logging
1011
import os
1112
from typing import Dict, List, Union
@@ -70,12 +71,30 @@ def get_taskcluster_client(service: str):
7071

7172

7273
def _handle_artifact(path, response):
74+
# When taskcluster client returns non-JSON responses, it wraps them in {"response": <Response>}
75+
# When it returns JSON, it's already parsed
76+
if isinstance(response, dict) and "response" in response:
77+
response = response["response"]
78+
7379
if path.endswith(".json"):
80+
# If response is already a dict (parsed JSON), return it directly
81+
if isinstance(response, dict):
82+
return response
7483
return response.json()
7584

7685
if path.endswith(".yml"):
7786
return yaml.load_stream(response.content)
7887

88+
# For non-JSON/YAML content, return raw response content
89+
if getattr(response, "raw", None):
90+
# Try to read from raw, but if it's empty, fall back to content
91+
content = response.raw.read()
92+
if not content and hasattr(response, "content"):
93+
content = response.content
94+
return io.BytesIO(content)
95+
elif hasattr(response, "content"):
96+
return io.BytesIO(response.content)
97+
7998
response.raw.read = functools.partial(response.raw.read, decode_content=True)
8099
return response.raw
81100

test/test_util_taskcluster.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def test_get_artifact_url(monkeypatch):
8484
assert tc.get_artifact_url(task_id, path) == expected_proxy
8585

8686

87-
@pytest.mark.xfail
8887
def test_get_artifact(responses, root_url):
8988
tid = "abc123"
9089
tc.get_taskcluster_client.cache_clear()
@@ -194,7 +193,6 @@ def test_find_task_id_batched(responses, root_url):
194193
assert result == {"index.abc": "abc", "index.def": "def"}
195194

196195

197-
@pytest.mark.xfail
198196
def test_get_artifact_from_index(responses, root_url):
199197
index = "foo"
200198
path = "file.txt"

0 commit comments

Comments
 (0)