{"record":{"id":"75e79e116ef5a258","repo":"siyuan-note/siyuan","slug":"copied-attribute-view-s-view-mapping-not-found","errorCode":null,"errorMessage":"copied attribute view [%s] view mapping not found","messagePattern":"copied attribute view \\[(.+?)\\] view mapping not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":742,"sourceCode":"\t\t}\n\t}\n}\n\nfunc applyTemplateAttributeViewPlan(node *ast.Node, plan *templateAttributeViewPlan) (*av.View, error) {\n\tnode.RemoveIALAttr(templateDatabaseModeAttr)\n\tif TemplateDatabaseModeCopy == plan.mode {\n\t\t// 完整复制会断开关联字段，实例上下文筛选不再有有效的目标数据库。\n\t\tnode.RemoveIALAttr(av.NodeAttrContextFilter)\n\t}\n\tif nil == plan.source || nil == plan.target || nil == plan.selectedView {\n\t\treturn nil, nil\n\t}\n\tnode.AttributeViewID = plan.target.ID\n\tviewID := plan.selectedView.ID\n\tif TemplateDatabaseModeCopy == plan.mode && nil != plan.copiedViewIDs {\n\t\tviewID = plan.copiedViewIDs[viewID]\n\t\tif \"\" == viewID {\n\t\t\treturn nil, fmt.Errorf(\"copied attribute view [%s] view mapping not found\", plan.source.ID)\n\t\t}\n\t\tif sourceViewID := strings.TrimSpace(node.IALAttr(av.NodeAttrView)); \"\" != sourceViewID {\n\t\t\tif copiedViewID := plan.copiedViewIDs[sourceViewID]; \"\" != copiedViewID {\n\t\t\t\tnode.SetIALAttr(av.NodeAttrView, copiedViewID)\n\t\t\t} else {\n\t\t\t\tnode.RemoveIALAttr(av.NodeAttrView)\n\t\t\t}\n\t\t}\n\t\tif visibleViewIDs := strings.TrimSpace(node.IALAttr(av.NodeAttrVisibleViewIDs)); \"\" != visibleViewIDs {\n\t\t\tvar copiedVisibleViewIDs []string\n\t\t\tfor _, sourceViewID := range strings.Split(visibleViewIDs, \",\") {\n\t\t\t\tsourceViewID = strings.TrimSpace(sourceViewID)\n\t\t\t\tif copiedViewID := plan.copiedViewIDs[sourceViewID]; \"\" != copiedViewID {\n\t\t\t\t\tcopiedVisibleViewIDs = append(copiedVisibleViewIDs, copiedViewID)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif 0 < len(copiedVisibleViewIDs) {\n\t\t\t\tnode.SetIALAttr(av.NodeAttrVisibleViewIDs, strings.Join(copiedVisibleViewIDs, \",\"))","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L724-L760","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run the template render; a transient race usually resolves once the source database is stable.","Open the source database and confirm the selected view exists; re-select a valid view in the template block.","If reproducible, inspect the .av JSON for the missing view ID and rebuild the database."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"view mapping not found\") {\n    // retry after the source database stabilizes\n    time.Sleep(500 * time.Millisecond)\n    return renderTemplateWithMode(id, mode)\n}","preventionTips":["Avoid rendering templates concurrently with edits to their source databases","Do not delete views in a database while templates referencing it are being applied"],"tags":["go","attribute-view","copy","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}