{"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":538,"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":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template.go#L520-L556","documentation":"After cloning, copyTemplateAttributeView asserts the clone preserved every view. If len(source.Views) != len(target.Views) the clone silently dropped or duplicated views, so the copy is rejected. This protects the view-ID remapping loop that follows from index misalignment.","triggerScenarios":"Rendering a template with a copy-mode database whose Clone() implementation returns a target with a different number of Views than the source (e.g. clone skipped nil/broken views).","commonSituations":"Attribute view produced by an older or newer version of the av package where Clone behavior changed; corrupted view list in the source .av data.","solutions":["Verify the source attribute view's Views array is well-formed (no entries that Clone would drop) and re-save the database in the UI","Update/align the av package version so Clone copies all views; check git history of av.AttributeView.Clone for behavior changes","Retry the template render after rebuilding the attribute view index (Ctrl+F5 / reload)"],"exampleFix":"// before: source with a nil view entry that clone drops\nsrc.Views = append(src.Views, nil)\nret, err := copyTemplateAttributeView(src)\n// after: prune nil views before copying\nsrc.Views = slices.DeleteFunc(src.Views, func(v *av.View) bool { return v == nil })\nret, err := copyTemplateAttributeView(src)","handlingStrategy":"validation","validationCode":"if len(src.Views) == 0 { return errors.New(\"attribute view has no views\") }\n// clone then verify:\nif tgt := src.Clone(); tgt != nil && len(tgt.Views) != len(src.Views) { return errors.New(\"clone mismatch\") }","typeGuard":null,"tryCatchPattern":"ret, err := copyTemplateAttributeView(src)\nif err != nil {\n    logging.LogErrorf(\"clone views mismatch for av %s: %v\", src.ID, err)\n    return err\n}","preventionTips":["Avoid inserting nil or placeholder entries into Views","Keep av package versions consistent across kernel builds","Re-save the database after version upgrades"],"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"}