siyuan-note/siyuan · error · ErrKeyNotFound
key not found
Error message
key not found
What it means
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.
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
Example fix
// before
kv, err := attrView.GetKeyValues(keyID)
if err != nil { return err }
// after
kv, err := attrView.GetKeyValues(keyID)
if errors.Is(err, av.ErrKeyNotFound) {
// column was deleted concurrently; skip instead of failing the whole transaction
return nil
} else if err != nil {
return err
} Defensive patterns
Strategy: validation
Validate before calling
for keyID := range payload.KeyIDs {
if _, err := attrView.GetKey(keyID); errors.Is(err, av.ErrKeyNotFound) {
// drop or re-resolve the column reference before sending
}
} Type guard
func isKeyNotFound(err error) bool {
return errors.Is(err, av.ErrKeyNotFound)
} Try / catch
kv, err := attrView.GetKeyValues(keyID)
if errors.Is(err, av.ErrKeyNotFound) {
return nil // column deleted concurrently; skip
} else if err != nil {
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- item not found
- view not found
- attribute view [ ] not found in box [ ]
- attribute view spec is too new
- filter nesting depth exceeds the maximum allowed
AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18).
Data as JSON: /api/errors/35fecac49b78407f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/av.go:1297
if !gulu.File.IsDir(av) {
if err := os.MkdirAll(av, 0755); err != nil {
logging.LogErrorf("create attribute view dir failed: %s", err)
return
}
}
return
}
func GetAttributeViewI18n(key string) string {
return util.AttrViewLangs[util.Lang][key].(string)
}
var (
ErrAttributeViewNotFound = errors.New("attribute view not found")
ErrInvalidAttributeViewID = errors.New("invalid attribute view id")
ErrInvalidBoxID = errors.New("invalid box id")
ErrViewNotFound = errors.New("view not found")
ErrKeyNotFound = errors.New("key not found")
ErrItemNotFound = errors.New("item not found")
ErrWrongLayoutType = errors.New("wrong layout type")
ErrInvalidColumnAlign = errors.New("invalid column align")
ErrSpecTooNew = errors.New("attribute view spec is too new")
ErrFilterTooDeep = errors.New("filter nesting depth exceeds the maximum allowed")
)
const (
NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id
NodeAttrView = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443
NodeAttrVisibleViewIDs = "custom-sy-av-visible-views" // 用于标记数据库块显示的视图 ID,逗号分隔
NodeAttrViewStaticText = "custom-sy-av-s-text" // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔
)
View on GitHub (pinned to afa823b6b4)