{"record":{"id":"3a77b6f172e76aba","repo":"siyuan-note/siyuan","slug":"clone-attribute-view-s-failed","errorCode":null,"errorMessage":"clone attribute view [%s] failed","messagePattern":"clone attribute view \\[(.+?)\\] failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":619,"sourceCode":"\t\treturn nil, fmt.Errorf(\"attribute view [%s] has no available visible view\", attrView.ID)\n\t}\n\treturn\n}\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{}","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L601-L637","documentation":"copyTemplateAttributeView clones the source attribute view for template 'copy' mode via source.Clone(). If Clone returns nil — the av package signals an unrecoverable clone failure — this error is returned and template rendering stops. It surfaces internal clone failures rather than silently inserting an empty copy.","triggerScenarios":"Rendering/inserting a template whose database block uses copy mode (the default) when av.AttributeView.Clone() returns nil, which happens when the clone cannot be constructed from the source attribute view's data.","commonSituations":"Corrupted or partially loaded attribute view data, a source database whose storage JSON cannot be materialized into a clonable structure, or an upstream av.Clone regression after version changes.","solutions":["Open the source attribute view in the UI to confirm it loads and re-save it","Restore the database file (storage/av/) from sync history or backup","Recreate the database and regenerate the template","Check for a recent SiYuan/av change affecting Clone and update or report the issue"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const av = await getAttrView(avID);\nif (!av || !av.views) throw new Error(\"source attribute view not loadable\");","typeGuard":null,"tryCatchPattern":"try {\n  await insertTemplate(path);\n} catch (e) {\n  if (String(e).includes(\"clone attribute view\")) {\n    await restoreAttrViewFromHistory(avID); // then retry once\n  }\n}","preventionTips":["Confirm the source database opens in the UI before using it in templates","Keep sync/backup history enabled for storage/av data","Avoid external mutation of database files while rendering templates","Update SiYuan promptly when attribute-view bugs are fixed"],"tags":["attribute-view","clone","template"],"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"}