From 5014c4428bba57dde14f2cb05c066df29368649e Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 23 May 2024 00:42:01 -0400 Subject: [PATCH] [scrobbles] Allow junk in the scrobble log --- vrobbler/apps/scrobbles/dataclasses.py | 14 ++++++++++++-- vrobbler/apps/scrobbles/models.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vrobbler/apps/scrobbles/dataclasses.py b/vrobbler/apps/scrobbles/dataclasses.py index 61c6f8f..d869c62 100644 --- a/vrobbler/apps/scrobbles/dataclasses.py +++ b/vrobbler/apps/scrobbles/dataclasses.py @@ -1,6 +1,6 @@ +import inspect import json -from dataclasses import dataclass, asdict - +from dataclasses import asdict, dataclass from typing import Optional @@ -23,6 +23,16 @@ class JSONMetadata(object): def json(self): return json.dumps(self.asdict) + @classmethod + def from_dict(cls, env): + return cls( + **{ + k: v + for k, v in env.items() + if k in inspect.signature(cls).parameters + } + ) + @dataclass class BoardGameScore(JSONMetadata): diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 0e6d046..a4d55d8 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -622,7 +622,7 @@ class Scrobble(TimeStampedModel): ) return None - return metadata_cls(**self.log) + return metadata_cls.from_dict(self.log) @property def tzinfo(self):