{"record":{"id":"d2ea59ed3d27c846","repo":"dgraph-io/badger","slug":"setentryat-can-only-be-used-in-managed-mode-use-s","errorCode":null,"errorMessage":"SetEntryAt can only be used in managed mode. Use SetEntry instead","messagePattern":"SetEntryAt can only be used in managed mode\\. Use SetEntry instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"batch.go","lineNumber":130,"sourceCode":"\treturn err\n}\n\nfunc (wb *WriteBatch) WriteList(kvList *pb.KVList) error {\n\twb.Lock()\n\tdefer wb.Unlock()\n\tfor _, kv := range kvList.Kv {\n\t\tif err := wb.writeKV(kv); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\n// SetEntryAt is the equivalent of Txn.SetEntry but it also allows setting version for the entry.\n// SetEntryAt can be used only in managed mode.\nfunc (wb *WriteBatch) SetEntryAt(e *Entry, ts uint64) error {\n\tif !wb.db.opt.managedTxns {\n\t\treturn errors.New(\"SetEntryAt can only be used in managed mode. Use SetEntry instead\")\n\t}\n\te.version = ts\n\treturn wb.SetEntry(e)\n}\n\n// Should be called with lock acquired.\nfunc (wb *WriteBatch) handleEntry(e *Entry) error {\n\tif err := wb.txn.SetEntry(e); err != ErrTxnTooBig {\n\t\treturn err\n\t}\n\t// Txn has reached it's zenith. Commit now.\n\tif cerr := wb.commit(); cerr != nil {\n\t\treturn cerr\n\t}\n\t// This time the error must not be ErrTxnTooBig, otherwise, we make the\n\t// error permanent.\n\tif err := wb.txn.SetEntry(e); err != nil {\n\t\twb.err.Store(err)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/batch.go#L112-L148","documentation":"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.","triggerScenarios":"Calling wb.SetEntryAt(e, ts) on a WriteBatch created by NewWriteBatch() (user mode).","commonSituations":"Copy-pasting managed-mode batch code into user-mode code; enabling/disabling WithManagedTransactions across environments while sharing the same writer helper.","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"],"exampleFix":"// before\nwb.SetEntryAt(e, ts) // user mode\n// after\nwb.SetEntry(e)","handlingStrategy":"validation","validationCode":"if !managed {\n    return wb.SetEntry(e)\n}\nreturn wb.SetEntryAt(e, ts)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the batch's mode (user vs managed) before choosing Set/SetEntryAt","Propagate db options (managed flag) into writer helpers instead of hardcoding APIs"],"tags":["error","managed-transactions","write-batch","versioning"],"backgroundTag":"managed-mode-api-mismatch","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"}