diff --git a/src/backend/services/web/strategy_v2/serializers.py b/src/backend/services/web/strategy_v2/serializers.py index bc8aae90..49893c05 100644 --- a/src/backend/services/web/strategy_v2/serializers.py +++ b/src/backend/services/web/strategy_v2/serializers.py @@ -102,6 +102,12 @@ def _validate_strategy_type(self, validated_request_data: dict): raise serializers.ValidationError( gettext("control_id and control_version are required when strategy_type is model"), ) + # check control + if not ControlVersion.objects.filter( + control_id=validated_request_data["control_id"], + control_version=validated_request_data["control_version"], + ).exists(): + raise serializers.ValidationError(gettext("Control Version not Exists")) elif strategy_type == StrategyType.RULE.value: if validated_request_data.get("configs", {}).get("config_type") != RuleAuditConfigType.LINK_TABLE: return @@ -211,11 +217,6 @@ def validate(self, attrs: dict) -> dict: data = super().validate(attrs) # check type self._validate_strategy_type(data) - # check control - if not ControlVersion.objects.filter( - control_id=data["control_id"], control_version=data["control_version"] - ).exists(): - raise serializers.ValidationError(gettext("Control Version not Exists")) # check name if Strategy.objects.filter(strategy_name=attrs["strategy_name"]).exists(): raise serializers.ValidationError(gettext("Strategy Name Duplicate")) @@ -294,11 +295,6 @@ def validate(self, attrs: dict) -> dict: data = super().validate(attrs) # check type self._validate_strategy_type(data) - # check control - if not ControlVersion.objects.filter( - control_id=data["control_id"], control_version=data["control_version"] - ).exists(): - raise serializers.ValidationError(gettext("Control Version not Exists")) # check name if ( Strategy.objects.filter(strategy_name=attrs["strategy_name"])