{"record":{"id":"973b7660fb8bd463","repo":"dgraph-io/badger","slug":"errmanagedtxn","errorCode":"ErrManagedTxn","errorMessage":"Invalid API request. Not allowed to perform this action using ManagedDB","messagePattern":"Invalid API request\\. Not allowed to perform this action using ManagedDB","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":67,"sourceCode":"\t// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.\n\t// In such a case, GC can't be run.\n\tErrThresholdZero = stderrors.New(\n\t\t\"Value log GC can't run because threshold is set to zero\")\n\n\t// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.\n\tErrNoRewrite = stderrors.New(\n\t\t\"Value log GC attempt didn't result in any cleanup\")\n\n\t// ErrRejected is returned if a value log GC is called either while another GC is running, or\n\t// after DB::Close has been called.\n\tErrRejected = stderrors.New(\"Value log GC request rejected\")\n\n\t// ErrInvalidRequest is returned if the user request is invalid.\n\tErrInvalidRequest = stderrors.New(\"Invalid request\")\n\n\t// ErrManagedTxn is returned if the user tries to use an API which isn't\n\t// allowed due to external management of transactions, when using ManagedDB.\n\tErrManagedTxn = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action using ManagedDB\")\n\n\t// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when\n\t// NamespaceOffset is non-negative.\n\tErrNamespaceMode = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.\")\n\n\t// ErrInvalidDump if a data dump made previously cannot be loaded into the database.\n\tErrInvalidDump = stderrors.New(\"Data dump cannot be read\")\n\n\t// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.\n\tErrZeroBandwidth = stderrors.New(\"Bandwidth must be greater than zero\")\n\n\t// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows\n\tErrWindowsNotSupported = stderrors.New(\"Read-only mode is not supported on Windows\")\n\n\t// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9\n\tErrPlan9NotSupported = stderrors.New(\"Read-only mode is not supported on Plan 9\")","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L49-L85","documentation":"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.","triggerScenarios":"Calling db.View, db.Update, db.NewTransaction, or db.NewWriteBatchAtRuntime on a DB opened with WithManagedTxns(true).","commonSituations":"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.","solutions":["Use NewTransactionAt/CommitAt and the managed-mode APIs instead of View/Update","Switch to a non-managed DB (drop WithManagedTxns) if you want normal transactions","Audit call sites so only managed-mode-compatible APIs are used"],"exampleFix":"// before\ndb.Update(func(txn *Txn) error { ... })\n// after\ntxn := db.NewTransactionAt(timestamp, true)\n// ... operate on txn ...\ndb.CommitAt(commitTs, func(err error) {})","handlingStrategy":"type-guard","validationCode":"if usingManagedDB && (apiIsView || apiIsUpdate) { panic(\"use managed txn APIs\") }","typeGuard":"func isManagedTxnErr(err error) bool { return errors.Is(err, ErrManagedTxn) }","tryCatchPattern":"if err := db.Update(fn); err != nil {\n\tif errors.Is(err, ErrManagedTxn) {\n\t\t// switch to NewTransactionAt/CommitAt path\n\t}\n}","preventionTips":["Decide managed vs regular mode once at startup and centralize transaction helpers","Search the codebase for View/Update when enabling WithManagedTxns","Document the mode in your DB wrapper layer"],"tags":["badger","managed-db","transactions","api-misuse"],"backgroundTag":"api-not-allowed-in-mode","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}