diff --git a/backend/core/serializers.py b/backend/core/serializers.py index 0e3c95ae7..c741ef570 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -220,6 +220,20 @@ class Meta: model = Asset fields = "__all__" + def validate_parent_assets(self, parent_assets): + """ + Check that the assets graph will not contain cycles + """ + if not self.instance: + return parent_assets + if parent_assets: + for asset in parent_assets: + if self.instance in asset.ancestors_plus_self(): + raise serializers.ValidationError( + "errorAssetGraphMustNotContainCycles" + ) + return parent_assets + class AssetReadSerializer(AssetWriteSerializer): folder = FieldsRelatedField() diff --git a/frontend/messages/en.json b/frontend/messages/en.json index a58960796..50fd4a9b8 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -979,5 +979,6 @@ "attackPath": "Attack path", "attackPaths": "Attack paths", "currentCriticality": "Current criticality", - "residualCriticality": "Residual criticality" + "residualCriticality": "Residual criticality", + "errorAssetGraphMustNotContainCycles": "The asset graph must not contain cycles." }