{"record":{"id":"4f75edea58141268","repo":"siyuan-note/siyuan","slug":"database-field-name-and-type-are-required","errorCode":null,"errorMessage":"database field name and type are required","messagePattern":"database field name and type are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":74,"sourceCode":"\t}\n\tif \"\" == previousID && \"\" == nextID {\n\t\tif err = treenode.CheckContainerParent(parentID); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tif \"\" == layout {\n\t\tlayout = av.LayoutTypeTable\n\t}\n\tswitch layout {\n\tcase av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:\n\tdefault:\n\t\treturn nil, av.ErrWrongLayoutType\n\t}\n\n\tpreparedKeys := make([]*av.Key, 0, len(keySpecs))\n\tfor _, spec := range keySpecs {\n\t\tif nil == spec || \"\" == strings.TrimSpace(spec.Name) || \"\" == strings.TrimSpace(spec.Type) {\n\t\t\treturn nil, errors.New(\"database field name and type are required\")\n\t\t}\n\t\tkey, keyErr := newAttributeViewKey(ast.NewNodeID(), strings.TrimSpace(spec.Name), strings.TrimSpace(spec.Type), spec.Icon,\n\t\t\tav.DateDisplayFormatFull)\n\t\tif nil != keyErr {\n\t\t\treturn nil, keyErr\n\t\t}\n\t\tpreparedKeys = append(preparedKeys, key)\n\t}\n\n\tblockID, avID := ast.NewNodeID(), ast.NewNodeID()\n\tdata := fmt.Sprintf(`<div class=\"av\" data-node-id=\"%s\" data-av-id=\"%s\" data-type=\"NodeAttributeView\" data-av-type=\"%s\"></div>`,\n\t\tblockID, avID, layout)\n\toperation := &Operation{\n\t\tAction:     \"insert\",\n\t\tData:       data,\n\t\tParentID:   parentID,\n\t\tPreviousID: previousID,\n\t\tNextID:     nextID,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_create.go#L56-L92","documentation":"Each key spec passed to CreateAttributeViewDatabase must have a non-empty Name and Type; a nil spec, an all-whitespace name, or an empty type triggers this error. These specs define the database fields created in order, and both name and type are mandatory to build an av.Key. The check is fail-fast before any key is created.","triggerScenarios":"Calling CreateAttributeViewDatabase with keySpecs containing a nil entry, or an entry whose Name or Type is \"\" or whitespace (e.g. \" \"); the databaseCreate API handler forwarding such values from the request body.","commonSituations":"Dynamically built field lists where empty user input is not filtered; JSON requests omitting the type field; whitespace-only names pasted from a template.","solutions":["Ensure every key spec has a non-blank Name and a valid Type string before calling","Filter out nil specs from the slice: keys = slices.DeleteFunc(keys, func(s *AttributeViewCreateKey) bool { return s == nil })","Trim user input and reject empty names in the client before invoking the API"],"exampleFix":"// before\nspecs := []*model.AttributeViewCreateKey{{Name: \" \", Type: \"text\"}, nil}\nmodel.CreateAttributeViewDatabase(parentID, \"\", \"\", name, pk, layout, specs)\n// after\nspecs = slices.DeleteFunc(specs, func(s *model.AttributeViewCreateKey) bool {\n    return s == nil || strings.TrimSpace(s.Name) == \"\" || strings.TrimSpace(s.Type) == \"\"\n})\nmodel.CreateAttributeViewDatabase(parentID, \"\", \"\", name, pk, layout, specs)","handlingStrategy":"validation","validationCode":"for i, s := range specs {\n    if s == nil || strings.TrimSpace(s.Name) == \"\" || strings.TrimSpace(s.Type) == \"\" {\n        return fmt.Errorf(\"spec %d: name and type are required\", i)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"field name and type are required\") {\n    return sanitizeSpecsAndRetry(specs)\n}","preventionTips":["Trim and validate all user-supplied field names/types before building specs","Drop nil entries from dynamically assembled spec slices","Require the type field in client-side forms"],"tags":["validation","api","empty-value"],"backgroundTag":"empty-required-field","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"}