{"record":{"id":"d78d368ea57f35bd","repo":"siyuan-note/siyuan","slug":"relation-value-is-missing","errorCode":null,"errorMessage":"relation value is missing","messagePattern":"relation value is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":420,"sourceCode":"\t\tvar assets []*ValueAsset\n\t\tfor _, asset := range value.MAsset {\n\t\t\tif nil != asset && \"\" != strings.TrimSpace(asset.Content) {\n\t\t\t\tif AssetTypeFile != asset.Type && AssetTypeImage != asset.Type {\n\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","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L402-L438","documentation":"For KeyTypeRelation values, normalizeNewItemTemplateValue requires a non-nil Value.Relation object; otherwise it fails with 'relation value is missing'. Relation template values must identify the related blocks via Relation.BlockIDs, which the nil object cannot.","triggerScenarios":"A value passed through PruneInvalidNewItemTemplateFieldValues or normalizeNewItemTemplateFieldValues with KeyTypeRelation and Value.Relation == nil (relation object missing from the template value).","commonSituations":"Templates created before a relation was linked (no BlockIDs yet); plugins generating relation rows without populating the Relation struct.","solutions":["Populate the Relation object with the related block IDs","Use an empty Relation {\"relation\":{\"blockIDs\":[]}} if no blocks are related yet","Change the value type if no relation semantics are needed","Remove the invalid value prior to pruning"],"exampleFix":"// before\n{\"type\":\"relation\"}\n// after\n{\"type\":\"relation\",\"relation\":{\"blockIDs\":[\"20240101120000-abcdef\"]}}","handlingStrategy":"validation","validationCode":"if v.Type == av.KeyTypeRelation && v.Relation == nil {\n    return fmt.Errorf(\"relation value requires a relation object\")\n}","typeGuard":"func hasRelation(v *av.Value) bool { return v != nil && v.Type == av.KeyTypeRelation && v.Relation != nil }","tryCatchPattern":null,"preventionTips":["Initialize Relation (even with empty BlockIDs) for relation-typed values","Resolve relations via the API so BlockIDs are populated correctly","Validate templates after every schema change"],"tags":["attribute-view","relation","validation"],"backgroundTag":"null-argument","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"}