{"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":658,"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":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template.go#L640-L676","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-open and re-save the source database so its view list is current, then re-render the template","Remove the stale view reference: reset the node's custom-view IAL attribute and let the kernel pick the database's default view","Verify the selected view still exists in the source attribute view before rendering (source.Views contains selectedView.ID)"],"exampleFix":"// before: selecting a removed view id\nplan.selectedView = &av.View{ID: \"deleted-view-id\"}\n// after: resolve the view from the live source\nfor _, v := range source.Views { if v.ID == wantedID { plan.selectedView = v; break } }","handlingStrategy":"validation","validationCode":"if _, ok := plan.copiedViewIDs[plan.selectedView.ID]; !ok {\n    return errors.New(\"selected view has no clone mapping\")\n}","typeGuard":null,"tryCatchPattern":"viewID := plan.copiedViewIDs[plan.selectedView.ID]\nif viewID == \"\" {\n    // fall back to the target's first view\n    if len(plan.target.Views) > 0 { viewID = plan.target.Views[0].ID }\n}","preventionTips":["Re-render after any concurrent edit to the source database","Do not delete views from a database while a template referencing it is being rendered","Reset stale view IAL attributes on template nodes"],"tags":["go","attribute-view","mapping","internal"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}