{"record":{"id":"4ee94c7d1278afe8","repo":"siyuan-note/siyuan","slug":"errinvalidattributeviewcontextfilter","errorCode":"ErrInvalidAttributeViewContextFilter","errorMessage":"invalid attribute view context filter","messagePattern":"invalid attribute view context filter","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/context_filter.go","lineNumber":31,"sourceCode":"//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\npackage av\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n)\n\nconst AttributeViewContextFilterSpec = 1\n\nvar (\n\tErrInvalidAttributeViewContextFilter = errors.New(\"invalid attribute view context filter\")\n\tErrAttributeViewContextNotBound      = errors.New(\"current document is not bound to the context filter target database\")\n)\n\n// AttributeViewContextFilter 描述物理数据库块独有的上下文筛选配置。\ntype AttributeViewContextFilter struct {\n\tSpec  int    `json:\"spec\"`\n\tKeyID string `json:\"keyID\"`\n}\n\n// AttributeViewContextFilterField 描述可用于物理数据库块上下文筛选的关联字段。\ntype AttributeViewContextFilterField struct {\n\tID         string `json:\"id\"`\n\tName       string `json:\"name\"`\n\tIcon       string `json:\"icon\"`\n\tTargetAvID string `json:\"targetAvID\"`\n}\n\n// FilterContext 保存一次数据库块渲染所需的上下文筛选值，不参与持久化。","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/context_filter.go#L13-L49","documentation":"Sentinel error ErrInvalidAttributeViewContextFilter indicates an attribute view context filter (the per-physical-database-block filter config) is structurally invalid. ParseAttributeViewContextFilter returns it when JSON decoding fails, and Validate returns it when Spec is not the expected value (AttributeViewContextFilterSpec = 1), KeyID is blank, or the referenced view/attrView is missing.","triggerScenarios":"Parsing a context filter JSON with unknown fields or malformed JSON; constructing a filter with Spec != 1 or empty keyID; calling Validate with a filter referencing fields absent from the AttributeView.","commonSituations":"Hand-edited document/block attributes carrying the filter; format upgrades where spec changed; filters copied between databases with mismatched key IDs.","solutions":["Check the filter JSON: spec must equal 1 and keyID must be a non-empty database key ID","Remove unknown JSON fields — parsing uses DisallowUnknownFields","Re-create the context filter binding from the UI so spec/keyID are generated correctly"],"exampleFix":"// before\n{\"spec\": 2, \"keyID\": \"\"}\n// after\n{\"spec\": 1, \"keyID\": \"20240101120000-abcdefgh\"}","handlingStrategy":"validation","validationCode":"function isValidContextFilter(f) { return f && f.spec === 1 && typeof f.keyID === 'string' && f.keyID.trim() !== '' && Object.keys(f).every(k => ['spec','keyID'].includes(k)); }","typeGuard":"function isContextFilter(v) { return typeof v === 'object' && v !== null && v.spec === 1 && typeof v.keyID === 'string' && v.keyID.length > 0; }","tryCatchPattern":"try { filter = parseContextFilter(raw); filter.validate(attrView); } catch (e) { if (errors.is(e, ErrInvalidAttributeViewContextFilter)) { rebuildFilterBinding(); } else { throw e; } }","preventionTips":["Only generate filters through the UI/API, never by hand-editing attributes","Keep spec synchronized when the format version changes","Validate filters against the target AttributeView before use"],"tags":["validation","attribute-view","context-filter"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}