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()