{"record":{"id":"9c36b50678cec49d","repo":"hyperledger/fabric","slug":"history-database-is-not-enabled","errorCode":null,"errorMessage":"history database is not enabled","messagePattern":"history database is not enabled","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/handler.go","lineNumber":1011,"sourceCode":"\tif payload == nil {\n\t\ttxContext.CleanupQueryContext(iterID)\n\t\treturn nil, errors.New(\"marshal failed: proto: Marshal called with nil\")\n\t}\n\n\tpayloadBytes, err := proto.Marshal(payload)\n\tif err != nil {\n\t\ttxContext.CleanupQueryContext(iterID)\n\t\treturn nil, errors.Wrap(err, \"marshal failed\")\n\t}\n\n\tchaincodeLogger.Debugf(\"Got keys and values. Sending %s\", pb.ChaincodeMessage_RESPONSE)\n\treturn &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payloadBytes, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil\n}\n\n// Handles query to ledger history db\nfunc (h *Handler) HandleGetHistoryForKey(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {\n\tif txContext.HistoryQueryExecutor == nil {\n\t\treturn nil, errors.New(\"history database is not enabled\")\n\t}\n\titerID := h.UUIDGenerator.New()\n\tnamespaceID := txContext.NamespaceID\n\n\tgetHistoryForKey := &pb.GetHistoryForKey{}\n\terr := proto.Unmarshal(msg.Payload, getHistoryForKey)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unmarshal failed\")\n\t}\n\n\thistoryIter, err := txContext.HistoryQueryExecutor.GetHistoryForKey(namespaceID, getHistoryForKey.Key)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\n\ttotalReturnLimit := h.calculateTotalReturnLimit(nil)\n\n\ttxContext.InitializeQueryContext(iterID, historyIter)","sourceCodeStart":993,"sourceCodeEnd":1029,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/handler.go#L993-L1029","documentation":"HandleGetHistoryForKey guard: the peer answered a GetHistoryForKey query but the ledger history database is disabled in core.yaml (ledger.history.enableHistoryDatabase=false), so no history can be served.","triggerScenarios":"Thrown at core/chaincode/handler.go:1011 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set ledger.history.enableHistoryDatabase: true and restart the peer (history accrues from then on)","Rewrite the chaincode to avoid GetHistoryForKey if history is intentionally disabled"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}