{"record":{"id":"35fecac49b78407f","repo":"siyuan-note/siyuan","slug":"key-not-found","errorCode":null,"errorMessage":"key not found","messagePattern":"key not found","errorType":"http","errorClass":"ErrKeyNotFound","httpStatus":null,"severity":"error","filePath":"kernel/av/av.go","lineNumber":1297,"sourceCode":"\tif !gulu.File.IsDir(av) {\n\t\tif err := os.MkdirAll(av, 0755); err != nil {\n\t\t\tlogging.LogErrorf(\"create attribute view dir failed: %s\", err)\n\t\t\treturn\n\t\t}\n\t}\n\treturn\n}\n\nfunc GetAttributeViewI18n(key string) string {\n\treturn util.AttrViewLangs[util.Lang][key].(string)\n}\n\nvar (\n\tErrAttributeViewNotFound  = errors.New(\"attribute view not found\")\n\tErrInvalidAttributeViewID = errors.New(\"invalid attribute view id\")\n\tErrInvalidBoxID           = errors.New(\"invalid box id\")\n\tErrViewNotFound           = errors.New(\"view not found\")\n\tErrKeyNotFound            = errors.New(\"key not found\")\n\tErrItemNotFound           = errors.New(\"item not found\")\n\tErrWrongLayoutType        = errors.New(\"wrong layout type\")\n\tErrInvalidColumnAlign     = errors.New(\"invalid column align\")\n\tErrSpecTooNew             = errors.New(\"attribute view spec is too new\")\n\tErrFilterTooDeep          = errors.New(\"filter nesting depth exceeds the maximum allowed\")\n)\n\nconst (\n\tNodeAttrNameAvs        = \"custom-avs\"                 // 用于标记块所属的属性视图，逗号分隔 av id\n\tNodeAttrView           = \"custom-sy-av-view\"          // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443\n\tNodeAttrVisibleViewIDs = \"custom-sy-av-visible-views\" // 用于标记数据库块显示的视图 ID，逗号分隔\n\tNodeAttrViewStaticText = \"custom-sy-av-s-text\"        // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049\n\n\tNodeAttrViewNames = \"av-names\" // 用于临时标记块所属的属性视图名称，空格分隔\n)\n","sourceCodeStart":1279,"sourceCodeEnd":1313,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/av/av.go#L1279-L1313","documentation":"ErrKeyNotFound is the sentinel error returned by (av *AttributeView).GetKey (kernel/av/av.go:1100-1108) and GetKeyValues (kernel/av/av.go:1135-1143) when the requested keyID does not appear in av.KeyValues. Keys are the columns/fields of a SiYuan database; every filter, sort, calc, and cell operation resolves its target column through these lookups.","triggerScenarios":"Calling attrView.GetKey(keyID) or GetKeyValues(keyID) with a column ID that was deleted; transaction operations (e.g. setAttrViewCellAttrView at kernel/model/attribute_view.go:7742) receiving a stale keyID; filters/sorts/rollup configs still referencing a removed column; transaction-context fast paths (kernel/model/attribute_view.go:2530, 5391-5406) where the context map has no entry for the key.","commonSituations":"Two clients editing the same database: one deletes a column while the other still sends an update for it; a plugin replays a captured operation after the schema changed; data sync/rollback resurrects an old view config that names removed keys.","solutions":["Refresh the attribute-view schema (av.ParseAttributeView + read av.KeyValues) and re-resolve the column by name before sending its keyID","If the operation came from a stale UI, re-render the database so the frontend drops deleted columns","Guard call sites with errors.Is(err, av.ErrKeyNotFound) and treat it as a no-op skip rather than a hard failure for optional column operations","Run av.PruneInvalidNewItemTemplateFieldValues-style cleanup (or the av_fix.go upgraders) if the .av.json is known to carry dead references"],"exampleFix":"// before\nkv, err := attrView.GetKeyValues(keyID)\nif err != nil { return err }\n\n// after\nkv, err := attrView.GetKeyValues(keyID)\nif errors.Is(err, av.ErrKeyNotFound) {\n    // column was deleted concurrently; skip instead of failing the whole transaction\n    return nil\n} else if err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"for keyID := range payload.KeyIDs {\n    if _, err := attrView.GetKey(keyID); errors.Is(err, av.ErrKeyNotFound) {\n        // drop or re-resolve the column reference before sending\n    }\n}","typeGuard":"func isKeyNotFound(err error) bool {\n    return errors.Is(err, av.ErrKeyNotFound)\n}","tryCatchPattern":"kv, err := attrView.GetKeyValues(keyID)\nif errors.Is(err, av.ErrKeyNotFound) {\n    return nil // column deleted concurrently; skip\n} else if err != nil {\n    return err\n}","preventionTips":["Resolve columns by name against a freshly parsed AttributeView, then use the returned key.ID","Re-render the database after any add/remove-column transaction before issuing cell updates","In batch operations, tolerate ErrKeyNotFound for optional columns instead of aborting"],"tags":["siyuan","attribute-view","column","key","not-found","go"],"backgroundTag":"column-id-not-found","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}