siyuan-note/siyuan · error

validate attribute view context filter target: %w

Error message

validate attribute view context filter target: %w

What it means

Wraps resolveAttributeViewContextFilterTarget when a newly validated context filter cannot be resolved against the attribute view and its tree box. Validation passed, but finding the filter's concrete target (e.g. the referenced view/field) failed, so the kernel refuses to persist the filter. Skipped during undo/redo replay so historical configurations can still be restored.

Source

Thrown at kernel/model/attribute_view.go:5511

	if nil != err {
		return nil, err
	}
	node, tree, err := getAttributeViewInstanceNode(attrView, blockID)
	if nil != err {
		return nil, err
	}

	var value string
	keyID = strings.TrimSpace(keyID)
	if "" != keyID {
		ret = &av.AttributeViewContextFilter{Spec: av.AttributeViewContextFilterSpec, KeyID: keyID}
		// undo/redo 重放需要能恢复字段删除或改型后留下的旧配置;普通事务和公开 API 仍严格校验。
		if nil == tx || !tx.isReplay {
			if err = ret.Validate(attrView); nil != err {
				return nil, err
			}
			if _, err = resolveAttributeViewContextFilterTarget(attrView, ret, tree.Box); nil != err {
				return nil, fmt.Errorf("validate attribute view context filter target: %w", err)
			}
		}
		if value, err = ret.Marshal(); nil != err {
			return nil, err
		}
	}
	if value == node.IALAttr(av.NodeAttrContextFilter) {
		return
	}

	attrs := map[string]string{av.NodeAttrContextFilter: value}
	if nil != tx {
		err = setNodeAttrsWithTx(tx, node, tree, attrs)
	} else {
		err = setNodeAttrs(node, tree, attrs)
	}
	return
}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Confirm the keyID exists in the target attribute view before setting the filter (list fields via API)
  2. Re-create the missing field or choose an existing field as the filter target
  3. If restoring legacy configs, ensure the referenced fields are recreated with the same IDs first

Example fix

// before
setAvContextFilter(blockID, avID, removedKeyID);
// after
const keys = await getAvKeys(avID);
if (!keys.some(k => k.id === keyID)) throw new Error("key gone");
setAvContextFilter(blockID, avID, keyID);
Defensive patterns

Strategy: validation

Validate before calling

const keys = await getAvKeys(avID);
if (!keys.some(k => k.id === keyID)) throw new Error(`filter target key ${keyID} missing`);

Try / catch

try { await setAvContextFilter(blockID, avID, keyID); } catch (e) { if (String(e).includes("filter target")) await recreateFieldThenRetry(); else throw e; }

Prevention

When it happens

Trigger: Calling SetAttributeViewContextFilter with a keyID/filter whose target cannot be resolved in the current attribute view — typically referencing a field that no longer exists (or exists in a different view) in a non-replay transaction.

Common situations: Setting a filter referencing a deleted or renamed field; passing a keyID from another attribute view; a plugin restoring filters after fields were restructured.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/01fd76249aa59638. Report an issue: GitHub.