Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,13 @@ def write_artifact(filename, data):
import gzip # noqa: PLC0415

with gzip.open(path, "wb") as f:
f.write(json.dumps(data)) # type: ignore
if filename.endswith(".json.gz"):
f.write(json.dumps(data).encode("utf-8")) # type: ignore
else:
f.write(json.dumps(data)) # type: ignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has actually been broken this whole time. It's trying to write a str to a file opened in binary mode. I suspect it was regressed way back when we were migrating from Python 2 -> 3.

So you can simplify this and fix the bug by doing something like:

elif filename.endswith(".gz"):
    import gzip  # noqa: PLC0415

    with gzip.open(path, "wt", encoding="utf-8") as f:
        json.dump(data, f)

elif filename.endswith(".mm"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .mm is a mermaid diagram and specific to gecko_taskgraph. Instead of checking specifically for this extension, let's just write the data as long as it's a string. So change this to elif isinstance(data, str):

with open(path, "w") as f:
f.write(data)
else:
raise TypeError(f"Don't know how to write to {filename}")

Expand Down