siyuan-note/siyuan · error

copied attribute view [%s] view mapping not found

Error message

copied attribute view [%s] view mapping not found

What it means

When applying a copy-mode attribute view plan, the template node's selected view ID must map to a cloned view ID through plan.copiedViewIDs. An empty mapping means the clone succeeded but the specific view ID was not carried over, so rendering cannot proceed safely.

Source

Thrown at kernel/model/template.go:658

		}
	}
}

func applyTemplateAttributeViewPlan(node *ast.Node, plan *templateAttributeViewPlan) (*av.View, error) {
	node.RemoveIALAttr(templateDatabaseModeAttr)
	if TemplateDatabaseModeCopy == plan.mode {
		// 完整复制会断开关联字段,实例上下文筛选不再有有效的目标数据库。
		node.RemoveIALAttr(av.NodeAttrContextFilter)
	}
	if nil == plan.source || nil == plan.target || nil == plan.selectedView {
		return nil, nil
	}
	node.AttributeViewID = plan.target.ID
	viewID := plan.selectedView.ID
	if TemplateDatabaseModeCopy == plan.mode && nil != plan.copiedViewIDs {
		viewID = plan.copiedViewIDs[viewID]
		if "" == viewID {
			return nil, fmt.Errorf("copied attribute view [%s] view mapping not found", plan.source.ID)
		}
		if sourceViewID := strings.TrimSpace(node.IALAttr(av.NodeAttrView)); "" != sourceViewID {
			if copiedViewID := plan.copiedViewIDs[sourceViewID]; "" != copiedViewID {
				node.SetIALAttr(av.NodeAttrView, copiedViewID)
			} else {
				node.RemoveIALAttr(av.NodeAttrView)
			}
		}
		if visibleViewIDs := strings.TrimSpace(node.IALAttr(av.NodeAttrVisibleViewIDs)); "" != visibleViewIDs {
			var copiedVisibleViewIDs []string
			for _, sourceViewID := range strings.Split(visibleViewIDs, ",") {
				sourceViewID = strings.TrimSpace(sourceViewID)
				if copiedViewID := plan.copiedViewIDs[sourceViewID]; "" != copiedViewID {
					copiedVisibleViewIDs = append(copiedVisibleViewIDs, copiedViewID)
				}
			}
			if 0 < len(copiedVisibleViewIDs) {
				node.SetIALAttr(av.NodeAttrVisibleViewIDs, strings.Join(copiedVisibleViewIDs, ","))

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Re-open and re-save the source database so its view list is current, then re-render the template
  2. Remove the stale view reference: reset the node's custom-view IAL attribute and let the kernel pick the database's default view
  3. Verify the selected view still exists in the source attribute view before rendering (source.Views contains selectedView.ID)

Example fix

// before: selecting a removed view id
plan.selectedView = &av.View{ID: "deleted-view-id"}
// after: resolve the view from the live source
for _, v := range source.Views { if v.ID == wantedID { plan.selectedView = v; break } }
Defensive patterns

Strategy: validation

Validate before calling

if _, ok := plan.copiedViewIDs[plan.selectedView.ID]; !ok {
    return errors.New("selected view has no clone mapping")
}

Try / catch

viewID := plan.copiedViewIDs[plan.selectedView.ID]
if viewID == "" {
    // fall back to the target's first view
    if len(plan.target.Views) > 0 { viewID = plan.target.Views[0].ID }
}

Prevention

When it happens

Trigger: Rendering a template with a copy-mode database whose selectedView.ID (or the node's view IAL attribute) does not appear in the copiedViewIDs map produced by copyTemplateAttributeView.

Common situations: The source attribute view was mutated between cloning and applying (view deleted); a stale template referencing a view ID that no longer exists in the source database; race with concurrent database edits.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/75e79e116ef5a258. Report an issue: GitHub.