{"record":{"id":"17c5956c11646604","repo":"siyuan-note/siyuan","slug":"invalid-relation-block-id-s","errorCode":null,"errorMessage":"invalid relation block ID [%s]","messagePattern":"invalid relation block ID \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":424,"sourceCode":"\t\t\t\t\treturn nil, fmt.Errorf(\"invalid asset type [%s]\", asset.Type)\n\t\t\t\t}\n\t\t\t\tassets = append(assets, asset)\n\t\t\t}\n\t\t}\n\t\tvalue.MAsset = assets\n\t\tvalue.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\n\tcase KeyTypeCheckbox:\n\t\tif nil == value.Checkbox {\n\t\t\treturn nil, errors.New(\"checkbox value is missing\")\n\t\t}\n\t\tvalue.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\n\tcase KeyTypeRelation:\n\t\tif nil == value.Relation {\n\t\t\treturn nil, errors.New(\"relation value is missing\")\n\t\t}\n\t\tfor _, blockID := range value.Relation.BlockIDs {\n\t\t\tif !ast.IsNodeIDPattern(blockID) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid relation block ID [%s]\", blockID)\n\t\t\t}\n\t\t}\n\t\tvalue.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\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported value type [%s]\", key.Type)\n\t}\n\tvalue.Block, value.Template, value.Created, value.Updated, value.Rollup = nil, nil, nil, nil, nil\n\tvalue.ID = \"\"\n\tvalue.KeyID = \"\"\n\tvalue.BlockID = \"\"\n\tvalue.Type = key.Type\n\tvalue.IsDetached = false\n\tvalue.CreatedAt = 0\n\tvalue.UpdatedAt = 0\n\tvalue.IsRenderAutoFill = false\n\tif nil != value.Number {\n\t\tvalue.Number.Format = key.NumberFormat\n\t\tvalue.Number.FormattedContent = \"\"","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L406-L442","documentation":"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.","triggerScenarios":"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).","commonSituations":"Hand-written templates with placeholder IDs never replaced; IDs copied from other systems; block IDs from deleted/renamed blocks kept verbatim in templates.","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"],"exampleFix":"// before\n\"blockIDs\":[\"my-block\"]\n// after\n\"blockIDs\":[\"20240101120000-abcdefg\"]","handlingStrategy":"validation","validationCode":"for _, id := range v.Relation.BlockIDs {\n    if !ast.IsNodeIDPattern(id) {\n        return fmt.Errorf(\"bad block ID %q\", id)\n    }\n}","typeGuard":"func validBlockIDs(v *av.Value) bool {\n    for _, id := range v.Relation.BlockIDs {\n        if !ast.IsNodeIDPattern(id) { return false }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["attribute-view","relation","identifier-validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}