dgraph-io/badger · error

ErrManagedTxn

ErrManagedTxn

Error message

Invalid API request. Not allowed to perform this action using ManagedDB

What it means

ErrManagedTxn is returned when the user calls an API that is not permitted because transactions are externally managed (ManagedDB mode). In managed mode, Read/Write transactions are controlled via NewTransactionAt/Write/CommitAt, so regular per-operation txn APIs are forbidden. Defined in errors.go.

Source

Thrown at errors.go:67

	// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
	// In such a case, GC can't be run.
	ErrThresholdZero = stderrors.New(
		"Value log GC can't run because threshold is set to zero")

	// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
	ErrNoRewrite = stderrors.New(
		"Value log GC attempt didn't result in any cleanup")

	// ErrRejected is returned if a value log GC is called either while another GC is running, or
	// after DB::Close has been called.
	ErrRejected = stderrors.New("Value log GC request rejected")

	// ErrInvalidRequest is returned if the user request is invalid.
	ErrInvalidRequest = stderrors.New("Invalid request")

	// ErrManagedTxn is returned if the user tries to use an API which isn't
	// allowed due to external management of transactions, when using ManagedDB.
	ErrManagedTxn = stderrors.New(
		"Invalid API request. Not allowed to perform this action using ManagedDB")

	// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when
	// NamespaceOffset is non-negative.
	ErrNamespaceMode = stderrors.New(
		"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.")

	// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
	ErrInvalidDump = stderrors.New("Data dump cannot be read")

	// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
	ErrZeroBandwidth = stderrors.New("Bandwidth must be greater than zero")

	// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
	ErrWindowsNotSupported = stderrors.New("Read-only mode is not supported on Windows")

	// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9
	ErrPlan9NotSupported = stderrors.New("Read-only mode is not supported on Plan 9")

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Use NewTransactionAt/CommitAt and the managed-mode APIs instead of View/Update
  2. Switch to a non-managed DB (drop WithManagedTxns) if you want normal transactions
  3. Audit call sites so only managed-mode-compatible APIs are used

Example fix

// before
db.Update(func(txn *Txn) error { ... })
// after
txn := db.NewTransactionAt(timestamp, true)
// ... operate on txn ...
db.CommitAt(commitTs, func(err error) {})
Defensive patterns

Strategy: type-guard

Validate before calling

if usingManagedDB && (apiIsView || apiIsUpdate) { panic("use managed txn APIs") }

Type guard

func isManagedTxnErr(err error) bool { return errors.Is(err, ErrManagedTxn) }

Try / catch

if err := db.Update(fn); err != nil {
	if errors.Is(err, ErrManagedTxn) {
		// switch to NewTransactionAt/CommitAt path
	}
}

Prevention

When it happens

Trigger: Calling db.View, db.Update, db.NewTransaction, or db.NewWriteBatchAtRuntime on a DB opened with WithManagedTxns(true).

Common situations: Reusing non-managed transaction code after switching Open options to managed mode; mixing managed and unmanaged APIs in the same application; DSN/configuration-driven mode changes the team did not account for.

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/973b7660fb8bd463. Report an issue: GitHub.