From fcae006afafd561d98d4ed364283a67851bf993d Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 20 Oct 2025 22:42:01 -0700 Subject: [PATCH] Tweak: improve tag parent validation error handling (#11096) --- src/documents/models.py | 2 +- src/documents/serialisers.py | 2 +- src/documents/tests/test_tag_hierarchy.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/documents/models.py b/src/documents/models.py index ea8662023..4794bc82f 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -132,7 +132,7 @@ class Tag(MatchingModel, TreeNodeModel): height = 0 if self.pk is None else self.get_depth() deepest_new_depth = (new_parent_depth + 1) + height if deepest_new_depth > self.MAX_NESTING_DEPTH: - raise ValidationError(_("Maximum nesting depth exceeded.")) + raise ValidationError({"parent": _("Maximum nesting depth exceeded.")}) return super().clean() diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index da9bef1ea..18d570010 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -635,7 +635,7 @@ class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer): temp.clean() except ValidationError as e: logger.debug("Tag parent validation failed: %s", e) - raise serializers.ValidationError({"parent": _("Invalid parent tag.")}) + raise e return super().validate(attrs) diff --git a/src/documents/tests/test_tag_hierarchy.py b/src/documents/tests/test_tag_hierarchy.py index 6052b5c81..73fe81786 100644 --- a/src/documents/tests/test_tag_hierarchy.py +++ b/src/documents/tests/test_tag_hierarchy.py @@ -171,7 +171,7 @@ class TestTagHierarchy(APITestCase): ) assert resp_fail.status_code == 400 assert "parent" in resp_fail.data - assert "Invalid" in str(resp_fail.data["parent"]) + assert "Maximum nesting depth exceeded" in str(resp_fail.data["parent"]) def test_max_depth_on_move_subtree(self): a = Tag.objects.create(name="A2") @@ -191,7 +191,7 @@ class TestTagHierarchy(APITestCase): ) assert resp_fail.status_code == 400 assert "Maximum nesting depth exceeded" in str( - resp_fail.data["non_field_errors"], + resp_fail.data["parent"], ) # Moving X under C (depth 3) should be allowed (deepest becomes 5)