Skip to content

Commit f08043e

Browse files
committed
Fix get_artifact returning the TC API response instead of the artifact
This fixes a regression from 384afee where we started using the taskcluster python client instead of making requests manually. The artifacts route is special because the API returns some JSON as part of a 303 to the artifact's content URL. The previous code followed that 303. The python client does not. So instead we're getting the body which looks like this: `{"type": "s3/...", "url": "whereverthe303pointsat"}`. This fixed it by following the redirect manually to restore the previous behavior. I also fixed the test as the previous one was basically ignoring the fact that taskcluster was returning a 303 and was mocking as if it didn't exist. It's worth noting that while it restores the behavior of returning the artifact's content (as a ByteIO), it is still a breaking change as the previous code used to return a Response object. Fixes #812
1 parent 90a12a6 commit f08043e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def get_artifact(task_id, path):
170170
"""
171171
queue = get_taskcluster_client("queue")
172172
response = queue.getLatestArtifact(task_id, path)
173-
return _handle_artifact(path, response)
173+
artifact_response = requests.get(response["url"])
174+
return _handle_artifact(path, artifact_response)
174175

175176

176177
def list_artifacts(task_id):

test/test_util_taskcluster.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,41 @@ def test_get_artifact(responses, root_url):
110110

111111
# Test text artifact
112112
responses.get(
113-
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.txt",
113+
"http://foo.bar/artifact.txt",
114114
body=b"foobar",
115115
)
116+
responses.get(
117+
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.txt",
118+
body=b'{"type": "s3", "url": "http://foo.bar/artifact.txt"}',
119+
status=303,
120+
headers={"Location": "http://foo.bar/artifact.txt"},
121+
)
116122
raw = tc.get_artifact(tid, "artifact.txt")
117123
assert raw.read() == b"foobar"
118124

119125
# Test JSON artifact
126+
responses.get("http://foo.bar/artifact.json", json={"foo": "bar"})
120127
responses.get(
121128
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.json",
122-
json={"foo": "bar"},
129+
body=b'{"type": "s3", "url": "http://foo.bar/artifact.json"}',
130+
status=303,
131+
headers={"Location": "http://foo.bar/artifact.json"},
123132
)
124133
result = tc.get_artifact(tid, "artifact.json")
125134
assert result == {"foo": "bar"}
126135

127136
# Test YAML artifact
128137
expected_result = {"foo": b"\xe2\x81\x83".decode()}
129138
responses.get(
130-
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml",
139+
"http://foo.bar/artifact.yml",
131140
body=b'foo: "\xe2\x81\x83"',
132141
)
142+
responses.get(
143+
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml",
144+
body=b'{"type": "s3", "url": "http://foo.bar/artifact.yml"}',
145+
status=303,
146+
headers={"Location": "http://foo.bar/artifact.yml"},
147+
)
133148
result = tc.get_artifact(tid, "artifact.yml")
134149
assert result == expected_result
135150

0 commit comments

Comments
 (0)