From ab814c80cb867e98f3eb14c3c9ea88a7e45fc2e7 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 23 Dec 2024 14:55:17 +0100 Subject: [PATCH] feat: check serializer data before scenario perform write method --- backend/core/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/core/views.py b/backend/core/views.py index 915e0c054..3cb6b4d21 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1307,7 +1307,9 @@ class RiskScenarioViewSet(BaseModelViewSet): ordering_fields = ordering def _perform_write(self, serializer): - if not serializer.validated_data.get("ref_id"): + if not serializer.validated_data.get( + "ref_id" + ) and serializer.validated_data.get("risk_assessment"): risk_assessment = serializer.validated_data["risk_assessment"] ref_id = RiskScenario.get_default_ref_id(risk_assessment) serializer.validated_data["ref_id"] = ref_id