diff --git a/apps/analysis/serializers.py b/apps/analysis/serializers.py index 97c4d7d90c..d9e3fffd41 100644 --- a/apps/analysis/serializers.py +++ b/apps/analysis/serializers.py @@ -480,7 +480,7 @@ def update(self, instance, validated_data): class AnalysisCloneGqlSerializer(serializers.Serializer): - analysis_id = serializers.PrimaryKeyRelatedField(queryset=Analysis.objects.all(), required=True) + analysis_id = IntegerIDField() title = serializers.CharField(required=True, write_only=True) start_date = serializers.DateField(write_only=True, required=False, allow_null=True) end_date = serializers.DateField(required=True, write_only=True) @@ -494,6 +494,15 @@ def validate(self, data): ) return data + def validate_analysis_id(self, analysis_id): + analysis = Analysis.objects.filter( + project=self.context['request'].active_project, + pk=analysis_id + ).first() + if analysis is None: + raise serializers.ValidationError("Analysis does not exists") + return analysis + def create(self, validated_data): title = validated_data['title'] end_date = validated_data['end_date']