{"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":535,"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":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template.go#L517-L553","documentation":"copyTemplateAttributeView clones a source attribute view (database) when rendering a template that embeds a database in copy mode. This error is thrown when av.AttributeView.Clone() returns nil despite the source being non-nil, meaning the clone could not be produced. It is a defensive internal invariant check guarding the copy pipeline before view ID remapping.","triggerScenarios":"A template containing a database node in TemplateDatabaseModeCopy is rendered and source.Clone() returns nil (Clone rejected the source, e.g. an empty or structurally invalid attribute view for the given ID).","commonSituations":"Rendering a template whose referenced attribute view file is corrupt, empty, or was written by an incompatible version so Clone yields nil; database .av JSON missing required fields.","solutions":["Check that the source attribute view file (data/av/<id>.av or storage/av) exists, parses as JSON, and contains a valid ID matching the requested ID","Re-open the database in the SiYuan UI to let the kernel re-index or rebuild the attribute view, then retry the template render","If programmatically testing, ensure the source *av.AttributeView was produced by av.ParseAttributeView (not a zero-value struct) before calling copyTemplateAttributeView"],"exampleFix":"// before: passing a partially constructed attribute view\nret, err := copyTemplateAttributeView(&av.AttributeView{})\n// after: parse the real attribute view first\nsrc, err := av.ParseAttributeView(id)\nif err != nil { return err }\nret, err := copyTemplateAttributeView(src)","handlingStrategy":"validation","validationCode":"src, err := av.ParseAttributeView(id)\nif err != nil || src == nil { return fmt.Errorf(\"attribute view %s unavailable\", id) }\n// then call copyTemplateAttributeView(src)","typeGuard":"if src == nil { return errors.New(\"nil attribute view\") }","tryCatchPattern":"if ret, err := copyTemplateAttributeView(src); err != nil {\n    logging.LogErrorf(\"copy av %s: %v\", src.ID, err)\n    return err\n}","preventionTips":["Always obtain the source via av.ParseAttributeView, never construct it by hand","Keep .av files valid JSON with a matching ID field","Re-save databases in the UI after manual storage edits"],"tags":["go","attribute-view","clone","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-14T05:17:10.506Z"}