{"record":{"id":"01fd76249aa59638","repo":"siyuan-note/siyuan","slug":"validate-attribute-view-context-filter-target-w","errorCode":null,"errorMessage":"validate attribute view context filter target: %w","messagePattern":"validate attribute view context filter target: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":5536,"sourceCode":"\tif nil != err {\n\t\treturn nil, err\n\t}\n\tnode, tree, err := getAttributeViewInstanceNode(attrView, blockID)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\n\tvar value string\n\tkeyID = strings.TrimSpace(keyID)\n\tif \"\" != keyID {\n\t\tret = &av.AttributeViewContextFilter{Spec: av.AttributeViewContextFilterSpec, KeyID: keyID}\n\t\t// undo/redo 重放需要能恢复字段删除或改型后留下的旧配置；普通事务和公开 API 仍严格校验。\n\t\tif nil == tx || !tx.isReplay {\n\t\t\tif err = ret.Validate(attrView); nil != err {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif _, err = resolveAttributeViewContextFilterTarget(attrView, ret, tree.Box); nil != err {\n\t\t\t\treturn nil, fmt.Errorf(\"validate attribute view context filter target: %w\", err)\n\t\t\t}\n\t\t}\n\t\tif value, err = ret.Marshal(); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tif value == node.IALAttr(av.NodeAttrContextFilter) {\n\t\treturn\n\t}\n\n\tattrs := map[string]string{av.NodeAttrContextFilter: value}\n\tif nil != tx {\n\t\terr = setNodeAttrsWithTx(tx, node, tree, attrs)\n\t} else {\n\t\terr = setNodeAttrs(node, tree, attrs)\n\t}\n\treturn\n}","sourceCodeStart":5518,"sourceCodeEnd":5554,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L5518-L5554","documentation":"When saving a database block's context filter, SiYuan validates the filter against the attribute view (ret.Validate) and then resolves the filter's target field/view (resolveAttributeViewContextFilterTarget). If the target cannot be resolved — for example the referenced key no longer exists or its type changed — the write is rejected and the underlying error is wrapped with this message. Undo/redo replays intentionally skip this strict validation.","triggerScenarios":"SetAttributeViewContextFilter (non-replay path, tx nil or tx.isReplay false) with a filter whose target key/view ID was deleted or re-typed since the filter was drafted — e.g. user deletes the column in another tab, then an older save lands.","commonSituations":"Saving a stale filter configuration after the target field was removed or its type changed; a client built the filter against a different database; concurrent edits removed the target between drafting and saving.","solutions":["Re-read the attribute view, rebuild the filter against existing field IDs, and retry","Restore the deleted/renamed target field or update the filter to point at the new field ID","If this arises during undo/redo, confirm the replay path (tx.isReplay) is set so validation is skipped as designed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const av = await fetchAv(avID);\nconst targetExists = av.fields.some(f => f.id === filter.keyID);\nif (!targetExists) throw new Error(`filter target ${filter.keyID} no longer exists`);","typeGuard":null,"tryCatchPattern":"try {\n  await api.setContextFilter(filter);\n} catch (e) {\n  if (/validate attribute view context filter target/.test(e.message)) {\n    const fresh = await rebuildFilterFromCurrentView(avID);\n    return api.setContextFilter(fresh);\n  }\n  throw e;\n}","preventionTips":["Rebuild filters from freshly fetched field lists right before saving","Avoid long gaps between drafting and saving a filter in concurrent editing sessions","Update stored filters when deleting or re-typing columns"],"tags":["attribute-view","filter","validation"],"backgroundTag":"schema-validation-failed","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"}