Undoing a tag rename leaves an unused destination parent

Open
#23,221 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
database, testing

Research direction

Start with ManageTagsViewModel.renameTag and the expansion restoration path; the issue says parent creation occurs outside undo history and points to a backend transaction change. Read the new ManageTagsRenameUndoRegressionTest.kt and run that regression test to reproduce the problem. Done means undo restores the original note tags and removes the unused destination parent from the tag cache.

Written by the indexing model from the issue text.

Description

upstream-issue

Assisted-by: GPT-6.1-Sol xhigh & GPT-6-Astra xhigh

Undoing a tag rename leaves an unused destination parent
Subject: Undoing a tag rename leaves an unused destination parent

Undoing an expanded branch rename restores note tags but leaves the destination parent in the tag list, blocking later renames to that name.

Fix unresolved: no compatible temporary fix verified.
Expansion restoration creates the parent outside undo history; preserving its creation and expansion together requires a backend transaction change.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/tags/ManageTagsRenameUndoRegressionTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/tags/ManageTagsRenameUndoRegressionTest.kt
new file mode 100644
index 0000000000..d587b1d8ee
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/tags/ManageTagsRenameUndoRegressionTest.kt
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.tags
+
+import com.ichi2.testutils.JvmTest
+import com.ichi2.testutils.rules.IcuCaseFoldingRule
+import com.ichi2.testutils.withViewModel
+import org.junit.Rule
+import org.junit.Test
+import kotlin.test.assertEquals
+
+class ManageTagsRenameUndoRegressionTest : JvmTest() {
+    @get:Rule
+    val caseFolding = IcuCaseFoldingRule()
+
+    @Test
+    fun `undoing an expanded branch rename removes the destination from the tag cache`() =
+        runTest {
+            val source = requireNotNull(TagName.build("source"))
+            val destination = requireNotNull(TagName.build("destination"))
+            val note = addBasicNote().update { addTag("source::child") }
+            withViewModel(ManageTagsViewModel()) {
+                toggleCollapsed(source).join()
+                val originalTags = col.tags.all().sorted()
+                renameTag(source, destination).join()
+                assertEquals(listOf("destination::child"), col.getNote(note.id).tags)
+
+                col.undo()
+
+                assertEquals(listOf("source::child"), col.getNote(note.id).tags)
+                assertEquals(originalTags, col.tags.all().sorted(), "Undo must also remove the unused destination parent")
+            }
+        }
+}

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/22849#pullrequestreview-5875867983

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.