From 95998ca3eb16005a92782a2ca07b4c47ed8d1c80 Mon Sep 17 00:00:00 2001 From: James Biggs Date: Thu, 14 Nov 2024 10:26:10 +0000 Subject: [PATCH] Update record serializing to handle None values --- etna/records/blocks.py | 12 +++++++----- etna/records/serializers.py | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/etna/records/blocks.py b/etna/records/blocks.py index 378a6f0d2..05bbae978 100644 --- a/etna/records/blocks.py +++ b/etna/records/blocks.py @@ -107,11 +107,13 @@ def extract_references(self, value): return [] def get_api_representation(self, value, context=None): - return { - "title": value.summary_title, - "iaid": value.iaid, - "reference_number": value.reference_number, - } + if value: + return { + "title": value.summary_title, + "iaid": value.iaid, + "reference_number": value.reference_number, + } + return None class Meta: icon = "archive" diff --git a/etna/records/serializers.py b/etna/records/serializers.py index 62841034d..af9be4e99 100644 --- a/etna/records/serializers.py +++ b/etna/records/serializers.py @@ -3,8 +3,10 @@ class RecordSerializer(serializers.Serializer): def to_representation(self, instance): - return { - "title": instance.summary_title, - "iaid": instance.iaid, - "reference_number": instance.reference_number, - } + if instance: + return { + "title": instance.summary_title, + "iaid": instance.iaid, + "reference_number": instance.reference_number, + } + return None