Skip to content

Commit

Permalink
fix releases edit serialization failure if Year is null
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 27, 2023
1 parent 60758de commit 7bfdc91
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rose/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ def from_cache(cls, release: CachedRelease, tracks: list[CachedTrack]) -> Metada
)

def serialize(self) -> str:
return tomli_w.dumps(asdict(self))
# LOL TOML DOESN'T HAVE A NULL TYPE. Use -9999 as sentinel. If your music is legitimately
# released in -9999, you should probably lay off the shrooms.
data = asdict(self)
data["year"] = self.year or -9999
return tomli_w.dumps(data)

@classmethod
def from_toml(cls, toml: str) -> MetadataRelease:
d = tomllib.loads(toml)
return cls(
title=d["title"],
releasetype=d["releasetype"],
year=d["year"],
year=d["year"] if d["year"] != -9999 else None,
genres=d["genres"],
labels=d["labels"],
artists=[MetadataArtist(name=a["name"], role=a["role"]) for a in d["artists"]],
Expand Down

0 comments on commit 7bfdc91

Please sign in to comment.