From a4b29c80733a3dec6458b165716a1c6703d899b5 Mon Sep 17 00:00:00 2001 From: abram axel booth Date: Mon, 9 Sep 2024 13:41:19 -0400 Subject: [PATCH] fix: (de)serializing null yearmonth --- osf/metrics/reports.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osf/metrics/reports.py b/osf/metrics/reports.py index cc2b4a83c22..7d37b1998c0 100644 --- a/osf/metrics/reports.py +++ b/osf/metrics/reports.py @@ -46,8 +46,10 @@ def deserialize(self, data): return YearMonth.from_str(data) elif isinstance(data, (datetime.datetime, datetime.date)): return YearMonth.from_date(data) + elif data is None: + return None else: - raise ValueError('unsure how to deserialize "{data}" (of type {type(data)}) to YearMonth') + raise ValueError(f'unsure how to deserialize "{data}" (of type {type(data)}) to YearMonth') def serialize(self, data): if isinstance(data, str): @@ -56,6 +58,8 @@ def serialize(self, data): return str(data) elif isinstance(data, (datetime.datetime, datetime.date)): return str(YearMonth.from_date(data)) + elif data is None: + return None else: raise ValueError(f'unsure how to serialize "{data}" (of type {type(data)}) as YYYY-MM')