How to Remove Orphaned Workspace Sidebar Items in Frappe
Remove orphaned Frappe Workspace Sidebar Items using frappe.get_all and frappe.delete_doc to fix TypeError in the frontend caused by missing workspace links.

This snippet demonstrates how to identify and remove orphaned Frappe Workspace Sidebar Items using `frappe.get_all` and `frappe.delete_doc` to resolve frontend TypeErrors.
It identifies and removes `Workspace Sidebar Item` records that reference non-existent `Workspace` documents, resolving related frontend errors.
Use this snippet after a Frappe/ERPNext version update or data migration where orphaned child table entries might cause UI issues.
| 1 | # Preview first |
| 2 | existing = set(frappe.get_all("Workspace", pluck="name")) |
| 3 | bad_items = frappe.get_all( |
| 4 | "Workspace Sidebar Item", |
| 5 | filters={"link_type": "Workspace"}, |
| 6 | fields=["name", "parent", "label", "link_to"] |
| 7 | ) |
| 8 | bad_items = [r for r in bad_items if r.link_to not in existing] |
| 9 | print(f"Found {len(bad_items)} orphaned items:") |
| 10 | for row in bad_items: |
| 11 | print(row) |
| 12 | |
| 13 | # Delete them |
| 14 | for row in bad_items: |
| 15 | frappe.delete_doc("Workspace Sidebar Item", row.name, ignore_permissions=True) |
| 16 | |
| 17 | frappe.db.commit() |
| 18 | print("Done. Deleted", len(bad_items), "orphaned sidebar items.") |
Understanding This Code
What It Does
Identifies and removes orphaned Workspace Sidebar Item records that reference non-existent Workspace documents, cleaning up database inconsistencies that cause frontend TypeErrors.
When To Use
Use this snippet after a Frappe/ERPNext version update or data migration where orphaned child table entries might cause UI issues. It's particularly useful when encountering 'TypeError: Cannot read properties of undefined (reading 'public')' errors in the frontend.
Prerequisites
- •Frappe/ERPNext installed and running.
- •Bench access or access to Frappe console.
- •Understanding of Frappe DocTypes and database operations.
Key Concepts
Important ideas to understand in this code
Workspace Sidebar Item
A child DocType linked to Workspace, defining items in its sidebar navigation.
Learn moreStep-by-Step Tutorial
Follow along to understand how this code works
Identify Existing Workspaces
Get a set of all active Workspace names to use for validating linked sidebar items.
existing = set(frappe.get_all("Workspace", pluck="name"))Find Orphaned Sidebar Items
Query all Workspace Sidebar Items and filter for those whose linked Workspace no longer exists.
bad_items = frappe.get_all(
"Workspace Sidebar Item",
filters={"link_type": "Workspace"},
fields=["name", "parent", "label", "link_to"]
)
bad_items = [r for r in bad_items if r.link_to not in existing]Delete Orphaned Records
Iterate through the identified orphaned items and delete each one using `frappe.delete_doc`, then commit the database changes.
for row in bad_items:
frappe.delete_doc("Workspace Sidebar Item", row.name, ignore_permissions=True)
frappe.db.commit()