siyuan-note/siyuan · error
invalid relation block ID [%s]
Error message
invalid relation block ID [%s]
What it means
Thrown inside normalizeNewItemTemplateValue (kernel/av/new_item_template.go:422-424) during the KeyTypeRelation branch, after confirming value.Relation is non-nil. Each string in value.Relation.BlockIDs is validated against ast.IsNodeIDPattern, which expects a 20-character alphanumeric SiYuan block ID. The first ID that fails the pattern check triggers this formatted error with the offending ID string.
Source
Thrown at kernel/av/new_item_template.go:424
return nil, fmt.Errorf("invalid asset type [%s]", asset.Type)
}
assets = append(assets, asset)
}
}
value.MAsset = assets
value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.Checkbox, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
case KeyTypeCheckbox:
if nil == value.Checkbox {
return nil, errors.New("checkbox value is missing")
}
value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Relation = nil, nil, nil, nil, nil, nil, nil, nil, nil
case KeyTypeRelation:
if nil == value.Relation {
return nil, errors.New("relation value is missing")
}
for _, blockID := range value.Relation.BlockIDs {
if !ast.IsNodeIDPattern(blockID) {
return nil, fmt.Errorf("invalid relation block ID [%s]", blockID)
}
}
value.Text, value.Number, value.Date, value.MSelect, value.URL, value.Email, value.Phone, value.MAsset, value.Checkbox = nil, nil, nil, nil, nil, nil, nil, nil, nil
default:
return nil, fmt.Errorf("unsupported value type [%s]", key.Type)
}
value.Block, value.Template, value.Created, value.Updated, value.Rollup = nil, nil, nil, nil, nil
value.ID = ""
value.KeyID = ""
value.BlockID = ""
value.Type = key.Type
value.IsDetached = false
value.CreatedAt = 0
value.UpdatedAt = 0
value.IsRenderAutoFill = false
if nil != value.Number {
value.Number.Format = key.NumberFormat
value.Number.FormattedContent = ""View on GitHub (pinned to 251596fc0d)
Solutions
- Replace invalid IDs with valid 20-character SiYuan block IDs obtained from the target Attribute View's blocks
- Verify each ID with ast.IsNodeIDPattern(id) before submitting
- If a referenced block was deleted, remove its ID from the BlockIDs list
Example fix
// before
value.Relation = &av.ValueRelation{BlockIDs: []string{"my-task", "short"}}
// after
value.Relation = &av.ValueRelation{BlockIDs: []string{"20240101120000abcdef01", "20240101120002fedcba03"}} Defensive patterns
Strategy: validation
Validate before calling
import "github.com/88250/lute/ast"
func validateRelationBlockIDs(value *av.Value) error {
if value.Relation == nil {
return nil
}
for _, id := range value.Relation.BlockIDs {
if !ast.IsNodeIDPattern(id) {
return fmt.Errorf("invalid block ID %q: must be a 20-char SiYuan node ID", id)
}
}
return nil
} Type guard
func isValidBlockID(id string) bool {
return ast.IsNodeIDPattern(id)
} Prevention
- Always use real SiYuan block IDs obtained from the target Attribute View, not human-readable names
- Validate every BlockID with ast.IsNodeIDPattern before submitting
- Remove stale block IDs of deleted blocks before saving the template
When it happens
Trigger: A relation-type template field value contains one or more block IDs that do not match the SiYuan node ID pattern (not 20 chars, contains invalid characters, or is empty).
Common situations: Using human-readable names instead of block IDs as relation targets; stale block IDs from deleted blocks; copy-pasting truncated IDs; manually constructing relation values without using real block IDs from the target AV.
Related errors
- relation value is missing
- email value is missing
- phone value is missing
- invalid asset type [%s]
- checkbox value is missing
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/17c5956c11646604.
Report an issue: GitHub.