{"record":{"id":"624d11c4f2f3d5b0","repo":"dgraph-io/dgraph","slug":"field-in-type-definition-must-have-a-name","errorCode":null,"errorMessage":"Field in type definition must have a name","messagePattern":"Field in type definition must have a name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":822,"sourceCode":"\n\t\t\t_, inSchema := schemaSet[fieldName]\n\t\t\t_, inRequest := reqPredSet[fieldName]\n\t\t\tif !inSchema && !inRequest {\n\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\"Schema does not contain a matching predicate for field %s in type %s\",\n\t\t\t\t\tfield.Predicate, t.TypeName)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// typeSanityCheck performs basic sanity checks on the given type update.\nfunc typeSanityCheck(t *pb.TypeUpdate) error {\n\tfor _, field := range t.Fields {\n\t\tif x.ParseAttr(field.Predicate) == \"\" {\n\t\t\treturn errors.Errorf(\"Field in type definition must have a name\")\n\t\t}\n\n\t\tif field.ValueType == pb.Posting_OBJECT && field.ObjectTypeName == \"\" {\n\t\t\treturn errors.Errorf(\n\t\t\t\t\"Field with value type OBJECT must specify the name of the object type\")\n\t\t}\n\n\t\tif field.Directive != pb.SchemaUpdate_NONE {\n\t\t\treturn errors.Errorf(\"Field in type definition cannot have a directive\")\n\t\t}\n\n\t\tif len(field.Tokenizer) > 0 {\n\t\t\treturn errors.Errorf(\"Field in type definition cannot have tokenizers\")\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":804,"sourceCodeEnd":840,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L804-L840","documentation":"typeSanityCheck validates each field in a pb.TypeUpdate. A field whose Predicate parses to an empty string via x.ParseAttr has no name, so Dgraph rejects the type update with this error. Every field in a type definition must reference a named predicate. It is raised from verifyTypes during type updates and is covered directly by TestTypeSanityCheck.","triggerScenarios":"A type update contains a field entry with an empty Predicate — e.g. a DQL type block with an empty line/trailing comma producing an anonymous field, or a programmatically built TypeUpdate with Fields entries whose Predicate is \"\" or a namespace-only attribute like \"ns@\" that ParseAttr reduces to empty.","commonSituations":"Generated schema payloads where the field-name variable is empty; hand-edited DQL leaving a stray comma in a type block; malformed JSON mutations with {\"fields\":[{\"predicate\":\"\"}]}; incorrect namespace prefix handling that strips the actual attribute name.","solutions":["Ensure each field in the type definition has a real predicate name (`type Person { name }`, not an empty entry)","Remove stray commas or blank lines from hand-written type blocks that yield anonymous fields","Fix the code/generator that constructs TypeUpdate so Fields entries with empty Predicate are skipped or rejected before sending","If namespaces are involved, verify the attribute includes its name after the namespace qualifier (ns@name, not just ns@)"],"exampleFix":"// before\n{\n  \"types\": [{\n    \"typeName\": \"Person\",\n    \"fields\": [{\"predicate\": \"\"}]\n  }]\n}\n\n// after\n{\n  \"types\": [{\n    \"typeName\": \"Person\",\n    \"fields\": [{\"predicate\": \"name\"}]\n  }]\n}","handlingStrategy":"validation","validationCode":"// Validate every type field has a non-empty predicate name before sending\nfor _, t := range mutation.Types {\n\tfor i, f := range t.Fields {\n\t\tif f.Predicate == \"\" {\n\t\t\treturn fmt.Errorf(\"type %q field[%d] has empty predicate\", t.TypeName, i)\n\t\t}\n\t}\n}","typeGuard":"func fieldsNamed(t *api.TypeUpdate) bool {\n\tfor _, f := range t.Fields {\n\t\tif f.Predicate == \"\" {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","tryCatchPattern":"_, err := txn.Mutate(ctx, mu)\nif err != nil && strings.Contains(err.Error(), \"Field in type definition must have a name\") {\n\treturn fmt.Errorf(\"anonymous field in type definition: %w\", err)\n}","preventionTips":["Reject type updates with empty Predicate fields at payload-construction time","Avoid trailing commas / blank lines inside DQL type blocks","Validate generator output so empty field-name variables never reach the mutation","If using namespaces, ensure attributes carry both namespace and name (ns@name)"],"tags":["schema","validation","dql","types"],"backgroundTag":"type-field-missing-name","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}