dgraph-io/dgraph · error

Empty predicate

Error message

Empty predicate

What it means

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.

Source

Thrown at schema/schema.go:533

}

// IndexingInProgress checks whether indexing is going on for a given predicate.
func (s *state) IndexingInProgress() bool {
	s.RLock()
	defer s.RUnlock()
	return len(s.mutSchema) > 0
}

// Init resets the schema state, setting the underlying DB to the given pointer.
func Init(ps *badger.DB) {
	pstore = ps
	reset()
}

// Load reads the latest schema for the given predicate from the DB.
func Load(predicate string) error {
	if len(predicate) == 0 {
		return errors.Errorf("Empty predicate")
	}
	State().DeleteMutSchema(predicate)
	key := x.SchemaKey(predicate)
	txn := pstore.NewTransactionAt(math.MaxUint64, false)
	defer txn.Discard()
	item, err := txn.Get(key)
	if err == badger.ErrKeyNotFound || err == badger.ErrBannedKey {
		return nil
	}
	if err != nil {
		return err
	}
	var s pb.SchemaUpdate
	err = item.Value(func(val []byte) error {
		x.Check(proto.Unmarshal(val, &s))
		return nil
	})
	if err != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure the predicate string is non-empty before calling schema.Load
  2. Validate/trim inputs derived from key parsing; reject keys with empty predicate segments
  3. Guard user-facing inputs so an empty predicate cannot reach Load

Example fix

// before
err := schema.Load(pred) // pred may be ""
// after
if pred == "" {
    return fmt.Errorf("skipping Load: empty predicate")
}
err := schema.Load(pred)
Defensive patterns

Strategy: validation

Validate before calling

func loadPredicate(pred string) error {
    if strings.TrimSpace(pred) == "" {
        return fmt.Errorf("refusing Load: empty predicate")
    }
    return schema.Load(pred)
}

Try / catch

if err := schema.Load(pred); err != nil {
    if strings.Contains(err.Error(), "Empty predicate") {
        log.Warn("skipping schema load for empty predicate key")
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling schema.Load("") directly, or indirectly via populateKeyValues/anonymous callers that pass an empty predicate parsed from a bad key.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/6c4be5af06b40e16. Report an issue: GitHub.