{"record":{"id":"07b8d46acca15409","repo":"siyuan-note/siyuan","slug":"clone-attribute-view-item-failed","errorCode":null,"errorMessage":"clone attribute view item failed","messagePattern":"clone attribute view item failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":337,"sourceCode":"\t\tvar cleanupErr error\n\t\tfor _, item := range items {\n\t\t\t_, _, detachErr := replaceAttributeViewBlock(avID, item.itemID, \"\", true, nil)\n\t\t\tcleanupErr = errors.Join(cleanupErr, detachErr)\n\t\t\t_, restoreErr := UpdateAttributeViewCell(nil, avID, item.original.KeyID, item.itemID, item.original)\n\t\t\tcleanupErr = errors.Join(cleanupErr, restoreErr)\n\t\t}\n\t\tcleanupErr = errors.Join(cleanupErr, cleanupCreatedDocs())\n\t\tReloadAttrView(avID)\n\t\treturn nil, newItemCreationError(err, cleanupErr)\n\t}\n\tret.Transaction = tx\n\treturn ret, nil\n}\n\nfunc newBoundAttributeViewItemValue(original *av.Value, docID, icon string) (*av.Value, error) {\n\tbound := original.Clone()\n\tif nil == bound || nil == bound.Block {\n\t\treturn nil, errors.New(\"clone attribute view item failed\")\n\t}\n\tbound.IsDetached = false\n\tbound.Block.ID = docID\n\tbound.Block.Content = \"\"\n\tbound.Block.Icon = icon\n\tbound.Block.RefSubtype = av.BlockRefSubtypeDynamic\n\treturn bound, nil\n}\n\nfunc lockAttributeViewItemDocs(avID string) func() {\n\tlockValue, _ := attributeViewItemDocsLocks.LoadOrStore(avID, &sync.Mutex{})\n\tlock := lockValue.(*sync.Mutex)\n\tlock.Lock()\n\treturn lock.Unlock\n}\n\nfunc attributeViewItemDocumentTemplate(attrView *av.AttributeView, saveMode string) (*av.NewItemTemplate, error) {\n\tswitch saveMode {","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L319-L355","documentation":"newBoundAttributeViewItemValue clones the original detached value and rewrites it into a bound value pointing at the new document. It errors when Clone() returns nil or the clone has no Block field, because a block-type value without Block data cannot be converted to a bound (non-detached) reference. Callers wrap this with the item ID (see error 1002).","triggerScenarios":"Called from CreateAttributeViewItemDocs for an item whose value.Clone() yields nil, or whose primary-key (block) value lacks the Block struct after cloning — typically due to corrupted attribute-view row data.","commonSituations":"Hand-edited .av JSON; rows produced by older format versions missing Block; test fixture data (this function is directly exercised by TestNewBoundAttributeViewItemValueUsesDynamicAnchorText) with a value whose Block is nil.","solutions":["Verify the item's primary-key value in the .av JSON has a non-null block object; recreate the row if it is missing","Reload/re-index the database so the value is re-read from disk, then retry the conversion","In tests, construct the input av.Value with a non-nil Block before calling newBoundAttributeViewItemValue"],"exampleFix":"// before\nbound := original.Clone()\nif nil == bound || nil == bound.Block {\n    return nil, errors.New(\"clone attribute view item failed\")\n}\n// after (caller-side guard)\nif original == nil || original.Block == nil {\n    return nil, fmt.Errorf(\"item value has no block data\")\n}\nbound := original.Clone()","handlingStrategy":"type-guard","validationCode":"if original == nil || original.Block == nil { return errors.New(\"value has no block data\") }","typeGuard":"func hasBlockValue(v *av.Value) bool { return v != nil && v.Block != nil }","tryCatchPattern":"bound, err := newBoundAttributeViewItemValue(original, docID, icon)\nif err != nil { return fmt.Errorf(\"item %s not bindable: %w\", itemID, err) }","preventionTips":["Ensure fixture/row values always carry a non-nil Block for block-type keys","Validate .av JSON after external edits","Re-index databases that fail this check"],"tags":["attribute-view","clone-failed","go-kernel"],"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"}