Skip to content

Commit 72bd324

Browse files
fix: skip duplicate leaf creation during v3 migration
The same Wiki Page can be referenced by sidebars in multiple Wiki Spaces. Wiki Document leaves require globally unique routes, so the second space's migration was raising ValidationError when it tried to create another leaf with the same wiki_page route. Skip and log instead during bench migrate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 02c8eec commit 72bd324

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

wiki/wiki/doctype/wiki_space/wiki_space.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ def _create_group_with_pages(self, group_label, items, sort_order):
123123
def _create_page_document(self, wiki_page_name, parent_group, sort_order):
124124
"""Create a leaf Wiki Document from a Wiki Page"""
125125
wiki_page = frappe.get_cached_doc("Wiki Page", wiki_page_name)
126+
127+
# The same Wiki Page can be referenced by sidebars in multiple Wiki Spaces.
128+
# Routes for leaves must be unique, so during migration the first space wins
129+
# and subsequent duplicates are skipped with a log.
130+
if (
131+
getattr(frappe.flags, "in_migrate", False)
132+
and wiki_page.route
133+
and frappe.db.exists("Wiki Document", {"route": wiki_page.route, "is_group": 0})
134+
):
135+
print(
136+
f"[wiki v3 migration] skipping duplicate leaf for Wiki Page "
137+
f"'{wiki_page_name}' (route '{wiki_page.route}') in space '{self.name}': "
138+
f"another sidebar already migrated this page."
139+
)
140+
return
141+
126142
leaf_doc = frappe.get_doc(
127143
{
128144
"doctype": "Wiki Document",

0 commit comments

Comments
 (0)