dgraph-io/dgraph · error
Field with value type OBJECT must specify the name of the ob
Error message
Field with value type OBJECT must specify the name of the object type
What it means
In Dgraph's type system, a type definition field declared with value type OBJECT represents a nested object edge and must name the concrete type it points to. typeSanityCheck (worker/mutation.go) validates every field of every type definition submitted via an Alter/type-verification request and rejects OBJECT fields whose ObjectTypeName is empty. Without the target type name, the object value cannot be resolved or validated, so the definition is refused.
Source
Thrown at worker/mutation.go:826
return errors.Errorf(
"Schema does not contain a matching predicate for field %s in type %s",
field.Predicate, t.TypeName)
}
}
}
return nil
}
// typeSanityCheck performs basic sanity checks on the given type update.
func typeSanityCheck(t *pb.TypeUpdate) error {
for _, field := range t.Fields {
if x.ParseAttr(field.Predicate) == "" {
return errors.Errorf("Field in type definition must have a name")
}
if field.ValueType == pb.Posting_OBJECT && field.ObjectTypeName == "" {
return errors.Errorf(
"Field with value type OBJECT must specify the name of the object type")
}
if field.Directive != pb.SchemaUpdate_NONE {
return errors.Errorf("Field in type definition cannot have a directive")
}
if len(field.Tokenizer) > 0 {
return errors.Errorf("Field in type definition cannot have tokenizers")
}
}
return nil
}
// CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction.
func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error) {
ctx, span := otel.Tracer("").Start(ctx, "worker.CommitOverNetwork")View on GitHub (pinned to 759e242be6)
Solutions
- Set the ObjectTypeName (or in DQL schema, the bracketed type like `friend: [Person] .`) for every OBJECT-valued field in the type definition
- Validate the type payload client-side before sending the alter request: for each field with ObjectType OBJECT assert ObjectTypeName != ""
- Check that any tool generating the schema (GraphQL schema converter, migration script) emits the referenced type name and that the referenced type itself is defined
Example fix
// before
{"fields":[{"predicate":"address","valueType":"OBJECT"}]}
// after
{"fields":[{"predicate":"address","valueType":"OBJECT","objectTypeName":"Address"}]} Defensive patterns
Strategy: validation
Validate before calling
for _, f := range typeDef.Fields {
if f.ValueType == pb.Posting_OBJECT && f.ObjectTypeName == "" {
return fmt.Errorf("field %q: OBJECT value type requires objectTypeName", f.Predicate)
}
} Type guard
func objectTypeNameSet(f *pb.SchemaUpdate) bool {
return f.ValueType != pb.Posting_OBJECT || f.ObjectTypeName != ""
} Prevention
- Never leave ObjectTypeName empty when emitting Posting_OBJECT fields from schema generators
- Define referenced object types in the same alter request
- Lint DQL type blocks for object fields lacking a bracketed target type
When it happens
Trigger: Submitting a type definition (via /alter with schema containing type blocks, or the Go/HTTP alter API) where a field has `object` as its value type but no target type is named, e.g. field generated from GraphQL-to-Dgraph conversion or hand-written JSON schema with ValueType OBJECT and ObjectTypeName "".
Common situations: Hand-authoring Dgraph schema JSON where nested object fields are declared but the referenced type name is omitted; programmatic schema generation that maps a field to Posting_OBJECT without filling ObjectTypeName; partial schema migrations that drop the object type reference.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Empty predicate
- Field in type definition cannot have a directive
- Field in type definition cannot have tokenizers
- illegal rune found "%c", expecting {
- JSON map is followed by illegal rune "%c"
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/49fbd7006ba15943.
Report an issue: GitHub.