siyuan-note/siyuan · error
invalid relation block ID
Error message
invalid relation block ID [%s]
What it means
Every block ID inside a relation value's BlockIDs must match the SiYuan node ID pattern (ast.IsNodeIDPattern); otherwise normalizeNewItemTemplateValue returns 'invalid relation block ID [%s]'. This guards template-created rows from pointing at nonexistent or malformed blocks.
Solutions
- Replace the entry with a valid block ID of form YYYYMMDDHHmmss-xxxxxxx obtained from the target block
- Remove the invalid block ID from BlockIDs
- Re-link the relation through the UI or API to regenerate correct IDs
- Run ast.IsNodeIDPattern on each ID before submitting
Example fix
// before "blockIDs":["my-block"] // after "blockIDs":["20240101120000-abcdefg"]
Defensive patterns
Strategy: validation
Validate before calling
for _, id := range v.Relation.BlockIDs {
if !ast.IsNodeIDPattern(id) {
return fmt.Errorf("bad block ID %q", id)
}
} Type guard
func validBlockIDs(v *av.Value) bool {
for _, id := range v.Relation.BlockIDs {
if !ast.IsNodeIDPattern(id) { return false }
}
return true
} Prevention
- Fetch real block IDs via the SQL/API instead of hard-coding placeholders
- Re-resolve relations after block deletion or renaming
- Use the regex IsNodeIDPattern enforces (14 digits + '-' + 7 alphanumerics) as a pre-submit lint
When it happens
Trigger: PruneInvalidNewItemTemplateFieldValues / normalizeNewItemTemplateFieldValues encounter a relation value whose BlockIDs contains a string that is not a valid 14-digit- timestamp-dash-7char node ID (e.g. a document title, a placeholder like "<block-id>", or an empty string).
Common situations: Hand-written templates with placeholder IDs never replaced; IDs copied from other systems; block IDs from deleted/renamed blocks kept verbatim in templates.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- database back relation changed since document deletion
- database back relation field
- database back relation value is invalid
- database back relation values
- existing back relation is invalid
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/17c5956c11646604.
Report an issue: GitHub.
Appendix: 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 9f775e8a12)