{"record":{"id":"4f10fcbec2873976","repo":"dgraph-io/dgraph","slug":"type-name-must-be-specified-in-type-update","errorCode":null,"errorMessage":"Type name must be specified in type update","messagePattern":"Type name must be specified in type update","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":765,"sourceCode":"\t\t\ttctx.Preds = append(tctx.Preds, res.ctx.Preds...)\n\t\t}\n\t}\n\tclose(resCh)\n\treturn tctx, e\n}\n\nfunc verifyTypes(ctx context.Context, m *pb.Mutations) error {\n\t// Create a set of all the predicates included in this schema request.\n\treqPredSet := make(map[string]struct{}, len(m.Schema))\n\tfor _, schemaUpdate := range m.Schema {\n\t\treqPredSet[schemaUpdate.Predicate] = struct{}{}\n\t}\n\n\t// Create a set of all the predicates already present in the schema.\n\tvar fields []string\n\tfor _, t := range m.Types {\n\t\tif t.TypeName == \"\" {\n\t\t\treturn errors.Errorf(\"Type name must be specified in type update\")\n\t\t}\n\n\t\tif err := typeSanityCheck(t); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor _, field := range t.Fields {\n\t\t\tfieldName := field.Predicate\n\t\t\tns, attr := x.ParseNamespaceAttr(fieldName)\n\t\t\tif attr[0] == '~' {\n\t\t\t\tfieldName = x.NamespaceAttr(ns, attr[1:])\n\t\t\t}\n\n\t\t\tif _, ok := reqPredSet[fieldName]; !ok {\n\t\t\t\tfields = append(fields, fieldName)\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L747-L783","documentation":"verifyTypes validates the Types list of a mutation request before applying type updates. Every pb.TypeUpdate must carry a non-empty TypeName; this error is returned when an entry in m.Types has an empty type name, so Dgraph cannot identify which type definition the update applies to. It is a client-side request validation error, not a server fault.","triggerScenarios":"Calling MutateOverNetwork (or the HTTP /mutate or gRPC Mutate APIs) with a payload whose types block contains a type definition with no name — e.g. an empty DQL type block `type { ... }`, a JSON mutation with {\"types\":[{\"fields\":[...]}]} missing the typeName field, or a programmatically built pb.TypeUpdate with TypeName unset.","commonSituations":"Hand-written DQL where `type Person {` lost its name; template/code generators that emit an empty type name; schema migration scripts that copy type bodies but drop the header; partial edits that leave a dangling anonymous type block.","solutions":["Give every type definition an explicit name: `type Person { name string }` instead of `type { name string }`","In JSON mutations, ensure each object in the types array has a non-empty typeName field","Audit generated or templated schema payloads for cases where the type name variable is empty or interpolated to \"\"","Validate the full mutation payload (types included) client-side before calling MutateOverNetwork"],"exampleFix":"// before\ntype {\n  name\n}\n\n// after\ntype Person {\n  name\n}","handlingStrategy":"validation","validationCode":"// Validate type updates before sending the mutation\nfor i, t := range mutation.Types {\n\tif t.TypeName == \"\" {\n\t\treturn fmt.Errorf(\"types[%d] has empty typeName\", i)\n\t}\n}","typeGuard":"func hasTypeName(t *api.TypeUpdate) bool {\n\treturn t != nil && t.TypeName != \"\"\n}","tryCatchPattern":"// DQL/HTTP client: wrap the mutate call and inspect the message\n_, err := txn.Mutate(ctx, mu)\nif err != nil && strings.Contains(err.Error(), \"Type name must be specified\") {\n\treturn fmt.Errorf(\"malformed type definition in mutation payload: %w\", err)\n}","preventionTips":["Never emit anonymous `type { ... }` blocks in DQL","Validate generated schema payloads against a template that requires a type name","Lint DQL type definitions in CI before deploying schema changes"],"tags":["schema","validation","dql","types"],"backgroundTag":"missing-type-name","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}