dgraph-io/badger · error
SetEntryAt can only be used in managed mode. Use SetEntry in
Error message
SetEntryAt can only be used in managed mode. Use SetEntry instead
What it means
SetEntryAt lets you stamp an explicit version on a batched entry, which is only meaningful in managed mode where the caller controls timestamps. In user mode Badger assigns versions internally, so this API returns an error (not a panic) directing you to SetEntry instead.
Source
Thrown at batch.go:130
return err
}
func (wb *WriteBatch) WriteList(kvList *pb.KVList) error {
wb.Lock()
defer wb.Unlock()
for _, kv := range kvList.Kv {
if err := wb.writeKV(kv); err != nil {
return err
}
}
return nil
}
// SetEntryAt is the equivalent of Txn.SetEntry but it also allows setting version for the entry.
// SetEntryAt can be used only in managed mode.
func (wb *WriteBatch) SetEntryAt(e *Entry, ts uint64) error {
if !wb.db.opt.managedTxns {
return errors.New("SetEntryAt can only be used in managed mode. Use SetEntry instead")
}
e.version = ts
return wb.SetEntry(e)
}
// Should be called with lock acquired.
func (wb *WriteBatch) handleEntry(e *Entry) error {
if err := wb.txn.SetEntry(e); err != ErrTxnTooBig {
return err
}
// Txn has reached it's zenith. Commit now.
if cerr := wb.commit(); cerr != nil {
return cerr
}
// This time the error must not be ErrTxnTooBig, otherwise, we make the
// error permanent.
if err := wb.txn.SetEntry(e); err != nil {
wb.err.Store(err)View on GitHub (pinned to 2a001d466f)
Solutions
- In user mode use wb.SetEntry(e) and let Badger assign the version
- Ensure the batch was created via NewWriteBatchAt / managed mode when explicit timestamps are required
- Branch on db.opt.managedTxns (or a config flag) to select SetEntry vs SetEntryAt
Example fix
// before wb.SetEntryAt(e, ts) // user mode // after wb.SetEntry(e)
Defensive patterns
Strategy: validation
Validate before calling
if !managed {
return wb.SetEntry(e)
}
return wb.SetEntryAt(e, ts) Prevention
- Check the batch's mode (user vs managed) before choosing Set/SetEntryAt
- Propagate db options (managed flag) into writer helpers instead of hardcoding APIs
When it happens
Trigger: Calling wb.SetEntryAt(e, ts) on a WriteBatch created by NewWriteBatch() (user mode).
Common situations: Copy-pasting managed-mode batch code into user-mode code; enabling/disabling WithManagedTransactions across environments while sharing the same writer helper.
Related errors
- cannot use NewWriteBatch in managed mode. Use NewWriteBatchA
- wb.err: %w err: %w
- cannot use NewWriteBatchAt with managedDB=false. Use NewWrit
- cannot use NewManagedWriteBatch with managedDB=false. Use Ne
- Update can only be used with managedDB=false.
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/d2ea59ed3d27c846.
Report an issue: GitHub.