siyuan-note/siyuan · error

copied attribute view

Error message

copied attribute view [%s] view mapping not found

What it means

After copying an attribute view (copy mode) during template rendering, each source view must map to a newly created view ID via plan.copiedViewIDs. If the selected view's ID has no mapping, the copy is inconsistent and the apply step aborts. This is an internal invariant of the copy pipeline.

Solutions

  1. Re-run the template render; a transient race usually resolves once the source database is stable.
  2. Open the source database and confirm the selected view exists; re-select a valid view in the template block.
  3. If reproducible, inspect the .av JSON for the missing view ID and rebuild the database.
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.Contains(err.Error(), "view mapping not found") {
    // retry after the source database stabilizes
    time.Sleep(500 * time.Millisecond)
    return renderTemplateWithMode(id, mode)
}

Prevention

When it happens

Trigger: applyTemplateAttributeViewPlan with plan.mode == TemplateDatabaseModeCopy where plan.selectedView.ID is absent from plan.copiedViewIDs — e.g. the copy completed but the selected view was removed or the mapping was built from a different source revision.

Common situations: Template rendered concurrently while the source database was edited (view deleted mid-render); a bug or corrupted .av file where the selected view ID does not exist in the source snapshot that was copied.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/75e79e116ef5a258. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template.go:742

		}
	}
}

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 9f775e8a12)