From a2f4c5aea0ea698355e2cad85420df0574bd6e76 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 14 Sep 2025 15:58:43 -0700 Subject: [PATCH] Some Sonar code smell suggestions --- src-ui/src/app/utils/flatten-tags.spec.ts | 6 +++--- src-ui/src/app/utils/flatten-tags.ts | 5 +++-- src/documents/tasks.py | 6 +++--- src/documents/tests/test_tag_hierarchy.py | 10 ---------- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src-ui/src/app/utils/flatten-tags.spec.ts b/src-ui/src/app/utils/flatten-tags.spec.ts index f39fd47fe..dd770f16c 100644 --- a/src-ui/src/app/utils/flatten-tags.spec.ts +++ b/src-ui/src/app/utils/flatten-tags.spec.ts @@ -34,17 +34,17 @@ describe('flattenTags', () => { expect(flat.map((t) => t.orderIndex)).toEqual([0, 1, 2, 3, 4, 5, 6]) // Children are rebuilt - const aRoot = flat.find((t) => t.name === 'A-root')! + const aRoot = flat.find((t) => t.name === 'A-root') expect(new Set(aRoot.children?.map((c) => c.name))).toEqual( new Set(['child 2', 'Child 10']) ) - const bRoot = flat.find((t) => t.name === 'B-root')! + const bRoot = flat.find((t) => t.name === 'B-root') expect(new Set(bRoot.children?.map((c) => c.name))).toEqual( new Set(['Alpha', 'beta']) ) - const child2 = flat.find((t) => t.name === 'child 2')! + const child2 = flat.find((t) => t.name === 'child 2') expect(new Set(child2.children?.map((c) => c.name))).toEqual( new Set(['Sub 1']) ) diff --git a/src-ui/src/app/utils/flatten-tags.ts b/src-ui/src/app/utils/flatten-tags.ts index c9758e1eb..f75a9020e 100644 --- a/src-ui/src/app/utils/flatten-tags.ts +++ b/src-ui/src/app/utils/flatten-tags.ts @@ -8,7 +8,7 @@ export function flattenTags(all: Tag[]): Tag[] { for (const t of map.values()) { if (t.parent) { const p = map.get(t.parent) - p && p.children.push(t) + p?.children.push(t) } } const roots = Array.from(map.values()).filter((t) => !t.parent) @@ -29,6 +29,7 @@ export function flattenTags(all: Tag[]): Tag[] { } } } - roots.sort(sortByName).forEach((r) => walk(r, 0)) + roots.sort(sortByName) + roots.forEach((r) => walk(r, 0)) return ordered } diff --git a/src/documents/tasks.py b/src/documents/tasks.py index 1f491a0e9..623bff064 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -522,7 +522,7 @@ def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None: When a tag's parent changes, ensure all documents containing the tag also have the parent tag (and its ancestors) applied. """ - DocumentTagRelationship = Document.tags.through + doc_tag_relationship = Document.tags.through doc_ids: list[int] = list( Document.objects.filter(tags=tag).values_list("pk", flat=True), @@ -540,13 +540,13 @@ def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None: missing_qs = Document.objects.filter(id__in=doc_ids).exclude(tags=parent) missing_ids = list(missing_qs.values_list("pk", flat=True)) to_create.extend( - DocumentTagRelationship(document_id=doc_id, tag_id=parent.id) + doc_tag_relationship(document_id=doc_id, tag_id=parent.id) for doc_id in missing_ids ) affected.update(missing_ids) if to_create: - DocumentTagRelationship.objects.bulk_create( + doc_tag_relationship.objects.bulk_create( to_create, ignore_conflicts=True, ) diff --git a/src/documents/tests/test_tag_hierarchy.py b/src/documents/tests/test_tag_hierarchy.py index bb9eb6a60..6052b5c81 100644 --- a/src/documents/tests/test_tag_hierarchy.py +++ b/src/documents/tests/test_tag_hierarchy.py @@ -31,16 +31,6 @@ class TestTagHierarchy(APITestCase): mime_type="application/pdf", ) - def test_api_add_child_adds_parent(self): - self.client.patch( - f"/api/documents/{self.document.pk}/", - {"tags": [self.child.pk]}, - format="json", - ) - self.document.refresh_from_db() - tags = set(self.document.tags.values_list("pk", flat=True)) - assert tags == {self.parent.pk, self.child.pk} - def test_document_api_add_child_adds_parent(self): self.client.patch( f"/api/documents/{self.document.pk}/",