From 5c81a34cbb933c961767c3186b56a252ce4fb832 Mon Sep 17 00:00:00 2001 From: sokumon Date: Mon, 12 Jan 2026 10:35:50 +0530 Subject: [PATCH] fix: remove orphan workspace sidebars --- frappe/model/sync.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frappe/model/sync.py b/frappe/model/sync.py index 19568ca8e4..73cf16a616 100644 --- a/frappe/model/sync.py +++ b/frappe/model/sync.py @@ -201,13 +201,16 @@ def remove_orphan_doctypes(): def remove_orphan_entities(): entites = ["Workspace", "Dashboard", "Page", "Report"] + app_level_entities = ["Workspace Sidebar"] entity_filter_map = { "Workspace": {"public": 1}, "Page": {"standard": "Yes"}, "Report": {"is_standard": "Yes"}, "Dashboard": {"is_standard": True}, + "Workspace Sidebar": {"standard": True}, } entity_file_map = create_entity_file_map(entites) + for entity in entites: print(f"Removing orphan {entity}s") all_enitities = frappe.get_all( @@ -228,6 +231,26 @@ def remove_orphan_entities(): print(e) # save the deleted icons frappe.db.commit() # nosemgrep + # Remove app level entities + for app_entity in app_level_entities: + print(f"Removing orphan {app_entity}s") + all_enitities = frappe.get_all( + app_entity, filters=entity_filter_map.get(app_entity), fields=["name", "app"] + ) + for i, w in enumerate(all_enitities): + if w.app and not check_if_record_exists("app", frappe.get_app_path(w.app), app_entity, w.name): + try: + print(f"Deleting entity {app_entity} {w.name}") + frappe.delete_doc(app_entity, w.name, force=True, ignore_missing=True) + update_progress_bar(f"Deleting orphaned {app_entity}", i, len(all_enitities)) + print() + + except Exception as e: + print(f"Error occurred while deleting entity: {app_entity} {w.name}") + print(e) + + # save the deleted icons + frappe.db.commit() # nosemgrep def create_entity_file_map(entities):