From 37316327a89f10574e23bd41c5d74d1728fc6efb Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Fri, 26 Apr 2024 00:13:19 +0200 Subject: [PATCH] Fix get_framework method --- backend/core/serializers.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/backend/core/serializers.py b/backend/core/serializers.py index 997a8ad9b..a2bd48817 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -511,21 +511,16 @@ def validate_score(self, value): def get_framework(self): if hasattr(self, "instance") and self.instance: return self.instance.compliance_assessment.framework - - # If for some reason the instance isn't set or doesn't have a compliance assessment, try the request data - # NOTE: I have no idea how this can happen at the time of writing this, adding guardrails just in case try: - compliance_assessment_data = self.context.get("request", {}).data.get( + compliance_assessment_id = self.context.get("request", {}).data.get( "compliance_assessment", {} ) - framework_id = compliance_assessment_data.get("framework") - if framework_id is not None: - return Framework.objects.get(id=framework_id) + compliance_assessment = ComplianceAssessment.objects.get( + id=compliance_assessment_id + ) + return compliance_assessment.framework except Framework.DoesNotExist: raise serializers.ValidationError("The specified framework does not exist.") - raise serializers.ValidationError( - "Framework information is required but was not provided." - ) class Meta: model = RequirementAssessment