{"record":{"id":"f34d00fabc29065e","repo":"siyuan-note/siyuan","slug":"clone-attribute-view-s-views-failed","errorCode":null,"errorMessage":"clone attribute view [%s] views failed","messagePattern":"clone attribute view \\[(.+?)\\] views failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":622,"sourceCode":"}\n\nfunc resolveCopyTemplateAttributeView(node *ast.Node, attrView *av.AttributeView) *av.View {\n\tif viewID := strings.TrimSpace(node.IALAttr(av.NodeAttrView)); \"\" != viewID {\n\t\tif view := attrView.GetView(viewID); nil != view {\n\t\t\treturn view\n\t\t}\n\t}\n\tview, _ := attrView.GetFirstView()\n\treturn view\n}\n\nfunc copyTemplateAttributeView(source *av.AttributeView) (ret *templateAttributeViewCopy, err error) {\n\ttarget := source.Clone()\n\tif nil == target {\n\t\treturn nil, fmt.Errorf(\"clone attribute view [%s] failed\", source.ID)\n\t}\n\tif len(source.Views) != len(target.Views) {\n\t\treturn nil, fmt.Errorf(\"clone attribute view [%s] views failed\", source.ID)\n\t}\n\tcopiedViewIDs := map[string]string{}\n\tfor i, sourceView := range source.Views {\n\t\tif nil == sourceView || nil == target.Views[i] {\n\t\t\treturn nil, fmt.Errorf(\"clone attribute view [%s] view failed\", source.ID)\n\t\t}\n\t\tcopiedViewIDs[sourceView.ID] = target.Views[i].ID\n\t}\n\treturn &templateAttributeViewCopy{target: target, copiedViewIDs: copiedViewIDs}, nil\n}\n\nfunc prepareTemplateAttributeViews(tree *parse.Tree, preview bool) (plans map[*ast.Node]*templateAttributeViewPlan,\n\tcopies []*templateAttributeViewCopy, err error) {\n\tplans = map[*ast.Node]*templateAttributeViewPlan{}\n\treferenceSources := map[string]*av.AttributeView{}\n\tcopySources := map[string]*av.AttributeView{}\n\tcopyBySourceID := map[string]*templateAttributeViewCopy{}\n\tboxID := templateAttributeViewBoxID(tree)","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L604-L640","documentation":"After cloning, copyTemplateAttributeView asserts the clone preserved the view list: len(source.Views) must equal len(target.Views). A mismatch means the clone dropped or duplicated views, so the copy would mis-map view IDs; this error aborts the template render. It is a defensive consistency check on the clone result.","triggerScenarios":"Copy-mode template rendering where av.AttributeView.Clone() returns a target whose Views slice length differs from the source — an internal inconsistency in the clone implementation or with concurrently mutated source data.","commonSituations":"Upstream av package changes that alter Clone semantics, race-y access to the source attribute view while it is being modified, or corrupted source data producing a partial clone.","solutions":["Retry the template insert after closing other editors touching the same database","Update SiYuan if a recent version changed attribute-view cloning; report the mismatch otherwise","Recreate/re-export the source database to get consistent view data","Check the source attribute view JSON for duplicated or malformed view entries"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const av = await getAttrView(avID);\nif (new Set(av.views.map(v => v.id)).size !== av.views.length) {\n  console.warn(\"duplicate view IDs in source attribute view\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await insertTemplate(path);\n} catch (e) {\n  if (String(e).includes(\"views failed\")) {\n    await sleep(200); await insertTemplate(path); // retry after concurrent writers settle\n  }\n}","preventionTips":["Avoid rendering templates while the same database is open for editing elsewhere","Report persistent clone mismatches as av-package bugs with the database JSON","Restore databases from history rather than patching cloned output"],"tags":["attribute-view","clone","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"}