]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Tweak: improve tag parent validation error handling (#11096)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 21 Oct 2025 05:42:01 +0000 (22:42 -0700)
committerGitHub <noreply@github.com>
Tue, 21 Oct 2025 05:42:01 +0000 (22:42 -0700)
src/documents/models.py
src/documents/serialisers.py
src/documents/tests/test_tag_hierarchy.py

index ea8662023dccbd73d402d31192374e7b020042f8..4794bc82fce6e1aaff02b1361d3e73fff4e4d017 100644 (file)
@@ -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()
 
index da9bef1ea3077aa3f3f7bc4712efe9f28e0b666a..18d5700101d11fceae459fd0aad59a7164153315 100644 (file)
@@ -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)
 
index 6052b5c81df5cba445e2c69a3f9c2ac433f5e669..73fe8178680a35423f7141313988d6b6efc3d0c2 100644 (file)
@@ -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)