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

  1. Replace the entry with a valid block ID of form YYYYMMDDHHmmss-xxxxxxx obtained from the target block
  2. Remove the invalid block ID from BlockIDs
  3. Re-link the relation through the UI or API to regenerate correct IDs
  4. 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

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


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)