Skip to content

Commit 278d36d

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 278d36d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,44 @@ 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+
f"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(
127+
f"http://foo.bar/artifact.json",
128+
json={"foo": "bar"}
129+
)
120130
responses.get(
121131
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.json",
122-
json={"foo": "bar"},
132+
body=b'{"type": "s3", "url": "http://foo.bar/artifact.json"}',
133+
status=303,
134+
headers={"Location": "http://foo.bar/artifact.json"}
123135
)
124136
result = tc.get_artifact(tid, "artifact.json")
125137
assert result == {"foo": "bar"}
126138

127139
# Test YAML artifact
128140
expected_result = {"foo": b"\xe2\x81\x83".decode()}
129141
responses.get(
130-
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml",
142+
f"http://foo.bar/artifact.yml",
131143
body=b'foo: "\xe2\x81\x83"',
132144
)
145+
responses.get(
146+
f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml",
147+
body=b'{"type": "s3", "url": "http://foo.bar/artifact.yml"}',
148+
status=303,
149+
headers={"Location": "http://foo.bar/artifact.yml"}
150+
)
133151
result = tc.get_artifact(tid, "artifact.yml")
134152
assert result == expected_result
135153

0 commit comments

Comments
 (0)