Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Check if new parent is not a descendant of current category

Marcin Gębala66b49f913513
diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.py
index 56e24181f1..522f5b0865 100644
--- a/saleor/dashboard/category/forms.py
+++ b/saleor/dashboard/category/forms.py
@@ -18,4 +18,6 @@ class CategoryForm(forms.ModelForm):
parent = self.cleaned_data['parent']
if parent == self.instance:
raise forms.ValidationError(_('A category may not be made a child of itself'))
+ if self.instance in parent.get_ancestors():
+ raise forms.ValidationError(_('A category may not be made a child of any of its descendants.'))
return parent