{"record":{"id":"f2b77a15f3e4bfa0","repo":"siyuan-note/siyuan","slug":"restored-database-entry-s-is-missing","errorCode":null,"errorMessage":"restored database entry [%s] is missing","messagePattern":"restored database entry \\[(.+?)\\] is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_block_undo.go","lineNumber":150,"sourceCode":"\t}\n\tif err := tx.replayAttributeViewFields(op); err != nil {\n\t\treturn err\n\t}\n\trestored, err := tx.readAttributeViewForMutation(op.AvID, state.blockID, state.boxID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar itemIDs []string\n\tfor _, src := range op.Srcs {\n\t\tid, _ := src[\"id\"].(string)\n\t\tnode, tree, err := getNodeByBlockID(tx, id)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\titemID, _ := src[\"itemID\"].(string)\n\t\tprimary := restored.GetBlockValue(itemID)\n\t\tif primary == nil || primary.Block == nil {\n\t\t\treturn fmt.Errorf(\"restored database entry [%s] is missing\", itemID)\n\t\t}\n\t\tattrs := parse.IAL2Map(node.KramdownIAL)\n\t\tids := strings.Split(attrs[av.NodeAttrNameAvs], \",\")\n\t\tif !slices.Contains(ids, op.AvID) {\n\t\t\tids = append(ids, op.AvID)\n\t\t}\n\t\tattrs[av.NodeAttrNameAvs] = strings.Trim(strings.Join(ids, \",\"), \",\")\n\t\tattrs[av.NodeAttrViewNames] = getAvNames(attrs[av.NodeAttrNameAvs])\n\t\tif primary.Block.RefSubtype == \"s\" {\n\t\t\tattrs[av.NodeAttrViewStaticText+\"-\"+op.AvID] = primary.Block.Content\n\t\t}\n\t\tif err = setNodeAttrsWithTx(tx, node, tree, attrs); err != nil {\n\t\t\treturn err\n\t\t}\n\t\titemIDs = append(itemIDs, itemID)\n\t}\n\top.RetData = &insertAttrViewBlockResult{InsertedItemIDs: itemIDs}\n\treturn nil","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_block_undo.go#L132-L168","documentation":"During undo of a transaction that inserted attribute-view (database) blocks, restoreDeletedAttributeViewBlocks re-adds previously deleted rows into the attribute view and then validates that the specific item (row) being restored exists in the restored collection. If GetBlockValue(itemID) returns nil — i.e. no block value with that item ID exists after restore — it aborts the transaction with this error. This is an internal consistency guard: the undo log references a database row that the restore operation could not actually materialize.","triggerScenarios":"Undoing a doInsertAttrViewBlock operation when the transaction's src.ID (itemID) does not match any row restored into the target attribute view; e.g. the database was modified, the row was permanently deleted, or the AV was unlinked between the original operation and the undo.","commonSituations":"Undo stack references stale data after the database table was deleted or re-created; concurrent edits removed the row; a corrupted or partially synced .sy file leaves the AV index without the expected item; undoing across a sync that replaced the document's databases.","solutions":["Verify the target database still exists and the row with the given itemID is present before triggering undo","Refresh/reload the document so the attribute-view index matches disk, then retry the undo","Check for sync or concurrent-edit conflicts that removed the row and resolve conflicts first","If reproducible, clear the undo stack for the affected document (re-open the document) and report the mismatch"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"av := getAttributeView(avID)\nitem := av.GetBlockValue(itemID)\nif item == nil || item.Block == nil { return fmt.Errorf(\"item %s no longer exists; undo unavailable\", itemID) }","typeGuard":"func canUndoAttrViewBlock(av *av.AttributeView, itemID string) bool {\n    v := av.GetBlockValue(itemID)\n    return v != nil && v.Block != nil\n}","tryCatchPattern":"if err := doUndo(tx); err != nil {\n    if strings.Contains(err.Error(), \"restored database entry\") {\n        refreshDocument(); return // undo stack stale, reload instead\n    }\n    return err\n}","preventionTips":["Do not permanently delete database rows while undoable operations referencing them are in the stack","Resolve sync conflicts before performing undo","Re-open documents whose databases were heavily edited so the undo stack resets to consistent state"],"tags":["undo","database","attribute-view","consistency"],"backgroundTag":"record-not-found","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"}