Fix: retrieve document_count for tag children (#11125)

This commit is contained in:
shamoon 2025-10-22 11:13:15 -07:00 committed by GitHub
parent 0ebd9f24b5
commit 13161ebb01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 71 additions and 15 deletions

View file

@ -9,6 +9,7 @@ from documents.models import Tag
from documents.models import Workflow
from documents.models import WorkflowAction
from documents.models import WorkflowTrigger
from documents.serialisers import TagSerializer
from documents.signals.handlers import run_workflows
@ -121,6 +122,31 @@ class TestTagHierarchy(APITestCase):
tags = set(self.document.tags.values_list("pk", flat=True))
assert tags == {self.parent.pk, orphan.pk}
def test_child_document_count_included_when_parent_paginated(self):
self.document.tags.add(self.child)
response = self.client.get(
"/api/tags/",
{"page_size": 1, "ordering": "-name"},
)
assert response.status_code == 200
assert response.data["results"][0]["id"] == self.parent.pk
children = response.data["results"][0]["children"]
assert len(children) == 1
child_entry = children[0]
assert child_entry["id"] == self.child.pk
assert child_entry["document_count"] == 1
def test_tag_serializer_populates_document_filter_context(self):
context = {}
serializer = TagSerializer(self.parent, context=context)
assert serializer.data # triggers serialization
assert "document_count_filter" in context
def test_cannot_set_parent_to_self(self):
tag = Tag.objects.create(name="Selfie")
resp = self.client.patch(