{"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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L402-L438","documentation":"Thrown inside normalizeNewItemTemplateValue (kernel/av/new_item_template.go:419-420) when key.Type == KeyTypeRelation but value.Relation is nil. The function must have a *ValueRelation (containing BlockIDs) to proceed. This check runs before the BlockID validation loop at line 422, so a nil Relation pointer always fails here first.","triggerScenarios":"Saving an Attribute View new-item template with a static-mode relation field whose Value JSON omits the \"relation\" sub-field or sets it to null.","commonSituations":"Programmatic template creation for relation fields that doesn't populate the Relation pointer; frontend serializing a relation value without the blockIDs array; using a template value from a non-relation field type.","solutions":["Include a non-null relation object with a BlockIDs array, e.g. {\"relation\": {\"blockIDs\": [\"2024010100000000abcd1234\"]}}","Omit the field from FieldValues if no default relation is needed","Set Value.Relation = &ValueRelation{BlockIDs: []string{...}} before persisting"],"exampleFix":"// before\nfieldValue.Value = &av.Value{Type: av.KeyTypeRelation}\n// after\nfieldValue.Value = &av.Value{Type: av.KeyTypeRelation, Relation: &av.ValueRelation{BlockIDs: []string{\"2024010100000000abcd1234\"}}}","handlingStrategy":"validation","validationCode":"func validateRelationValue(value *av.Value, key *av.Key) error {\n    if key.Type == av.KeyTypeRelation && value.Relation == nil {\n        return fmt.Errorf(\"relation key requires a non-nil Value.Relation\")\n    }\n    return nil\n}","typeGuard":"func hasRelationValue(v *av.Value) bool {\n    return v != nil && v.Relation != nil\n}","tryCatchPattern":null,"preventionTips":["Always populate Value.Relation with a *ValueRelation containing BlockIDs for relation-type template fields","Use a per-key-type factory to construct correct value sub-objects"],"tags":["attribute-view","validation","relation","new-item-template","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}