Skip to content

Commit

Permalink
fix: (de)serializing null yearmonth
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Sep 9, 2024
1 parent 8e5a21f commit a4b29c8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion osf/metrics/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')

Expand Down

0 comments on commit a4b29c8

Please sign in to comment.