diff --git a/api/utils/serializer/v1/serializer.py b/api/utils/serializer/v1/serializer.py index 78f8d1f6..c01746c3 100644 --- a/api/utils/serializer/v1/serializer.py +++ b/api/utils/serializer/v1/serializer.py @@ -297,9 +297,12 @@ class AbstractCompensationAPISerializerV1Mixin: """ deadlines = [] for entry in deadline_data: - deadline_type = entry["type"] - date = entry["date"] - comment = entry["comment"] + try: + deadline_type = entry["type"] + date = entry["date"] + comment = entry["comment"] + except KeyError: + raise ValueError(f"Invalid deadline content. Content was {entry} but should follow the specification") # Check on validity if deadline_type not in DeadlineType: @@ -341,11 +344,14 @@ class AbstractCompensationAPISerializerV1Mixin: """ states = [] for entry in states_data: - biotope_type = entry["biotope"] - biotope_details = [ - self._konova_code_from_json(e, CODELIST_BIOTOPES_EXTRA_CODES_ID) for e in entry["biotope_details"] - ] - surface = float(entry["surface"]) + try: + biotope_type = entry["biotope"] + biotope_details = [ + self._konova_code_from_json(e, CODELIST_BIOTOPES_EXTRA_CODES_ID) for e in entry["biotope_details"] + ] + surface = float(entry["surface"]) + except KeyError: + raise ValueError(f"Invalid biotope content. Content was {entry} but should follow the specification ") # Check on validity if surface <= 0: @@ -385,16 +391,19 @@ class AbstractCompensationAPISerializerV1Mixin: """ actions = [] for entry in actions_data: - action_types = [ - self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_ID) for e in entry["action_types"] - ] - action_details = [ - self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_DETAIL_ID) for e in entry["action_details"] - ] - amount = float(entry["amount"]) - # Mapping of old "qm" into "m²" - unit = UnitChoices.m2.value if entry["unit"] == "qm" else entry["unit"] - comment = entry["comment"] + try: + action_types = [ + self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_ID) for e in entry["action_types"] + ] + action_details = [ + self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_DETAIL_ID) for e in entry["action_details"] + ] + amount = float(entry["amount"]) + # Mapping of old "qm" into "m²" + unit = UnitChoices.m2.value if entry["unit"] == "qm" else entry["unit"] + comment = entry["comment"] + except KeyError: + raise ValueError(f"Invalid action content. Content was {entry} but should follow specification") # Check on validity if amount <= 0: