siyuan-note/siyuan · error
ErrInvalidAttributeViewContextFilter
ErrInvalidAttributeViewContextFilter
Error message
invalid attribute view context filter
What it means
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.
Source
Thrown at kernel/av/context_filter.go:31
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package av
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"strings"
)
const AttributeViewContextFilterSpec = 1
var (
ErrInvalidAttributeViewContextFilter = errors.New("invalid attribute view context filter")
ErrAttributeViewContextNotBound = errors.New("current document is not bound to the context filter target database")
)
// AttributeViewContextFilter 描述物理数据库块独有的上下文筛选配置。
type AttributeViewContextFilter struct {
Spec int `json:"spec"`
KeyID string `json:"keyID"`
}
// AttributeViewContextFilterField 描述可用于物理数据库块上下文筛选的关联字段。
type AttributeViewContextFilterField struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
TargetAvID string `json:"targetAvID"`
}
// FilterContext 保存一次数据库块渲染所需的上下文筛选值,不参与持久化。View on GitHub (pinned to 8641553a1f)
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
Example fix
// before
{"spec": 2, "keyID": ""}
// after
{"spec": 1, "keyID": "20240101120000-abcdefgh"} Defensive patterns
Strategy: validation
Validate before calling
function isValidContextFilter(f) { return f && f.spec === 1 && typeof f.keyID === 'string' && f.keyID.trim() !== '' && Object.keys(f).every(k => ['spec','keyID'].includes(k)); } Type guard
function isContextFilter(v) { return typeof v === 'object' && v !== null && v.spec === 1 && typeof v.keyID === 'string' && v.keyID.length > 0; } Try / catch
try { filter = parseContextFilter(raw); filter.validate(attrView); } catch (e) { if (errors.is(e, ErrInvalidAttributeViewContextFilter)) { rebuildFilterBinding(); } else { throw e; } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Hand-edited document/block attributes carrying the filter; format upgrades where spec changed; filters copied between databases with mismatched key IDs.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- validate attribute view context filter target: %w
- wrong layout type
- filter nesting depth exceeds the maximum allowed
- invalid id
- ErrFilterTooDeep
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/4ee94c7d1278afe8.
Report an issue: GitHub.