{"record":{"id":"6c4be5af06b40e16","repo":"dgraph-io/dgraph","slug":"empty-predicate","errorCode":null,"errorMessage":"Empty predicate","messagePattern":"Empty predicate","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/schema.go","lineNumber":533,"sourceCode":"}\n\n// IndexingInProgress checks whether indexing is going on for a given predicate.\nfunc (s *state) IndexingInProgress() bool {\n\ts.RLock()\n\tdefer s.RUnlock()\n\treturn len(s.mutSchema) > 0\n}\n\n// Init resets the schema state, setting the underlying DB to the given pointer.\nfunc Init(ps *badger.DB) {\n\tpstore = ps\n\treset()\n}\n\n// Load reads the latest schema for the given predicate from the DB.\nfunc Load(predicate string) error {\n\tif len(predicate) == 0 {\n\t\treturn errors.Errorf(\"Empty predicate\")\n\t}\n\tState().DeleteMutSchema(predicate)\n\tkey := x.SchemaKey(predicate)\n\ttxn := pstore.NewTransactionAt(math.MaxUint64, false)\n\tdefer txn.Discard()\n\titem, err := txn.Get(key)\n\tif err == badger.ErrKeyNotFound || err == badger.ErrBannedKey {\n\t\treturn nil\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar s pb.SchemaUpdate\n\terr = item.Value(func(val []byte) error {\n\t\tx.Check(proto.Unmarshal(val, &s))\n\t\treturn nil\n\t})\n\tif err != nil {","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/schema/schema.go#L515-L551","documentation":"schema.Load reads the latest schema for a predicate from the DB, and rejects an empty predicate name outright with 'Empty predicate'. It is a defensive guard: no DB lookup is attempted without a valid predicate key.","triggerScenarios":"Calling schema.Load(\"\") directly, or indirectly via populateKeyValues/anonymous callers that pass an empty predicate parsed from a bad key.","commonSituations":"Parsing corrupted or malformed posting-list keys where the predicate segment is empty; passing an unvalidated user-supplied predicate name into Load; off-by-one key parsing in custom tooling.","solutions":["Ensure the predicate string is non-empty before calling schema.Load","Validate/trim inputs derived from key parsing; reject keys with empty predicate segments","Guard user-facing inputs so an empty predicate cannot reach Load"],"exampleFix":"// before\nerr := schema.Load(pred) // pred may be \"\"\n// after\nif pred == \"\" {\n    return fmt.Errorf(\"skipping Load: empty predicate\")\n}\nerr := schema.Load(pred)","handlingStrategy":"validation","validationCode":"func loadPredicate(pred string) error {\n    if strings.TrimSpace(pred) == \"\" {\n        return fmt.Errorf(\"refusing Load: empty predicate\")\n    }\n    return schema.Load(pred)\n}","typeGuard":null,"tryCatchPattern":"if err := schema.Load(pred); err != nil {\n    if strings.Contains(err.Error(), \"Empty predicate\") {\n        log.Warn(\"skipping schema load for empty predicate key\")\n        return nil\n    }\n    return err\n}","preventionTips":["Validate non-empty predicate names before any schema.Load call","Sanitize predicates parsed from raw keys; reject empty segments","Trim user input before it reaches schema APIs"],"tags":["dgraph","schema","validation","empty-input"],"backgroundTag":"empty-predicate-name","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}