{"record":{"id":"fa9e5cc745ec0e8e","repo":"hyperledger/fabric","slug":"could-not-fetch-approved-chaincode-definition-nam","errorCode":null,"errorMessage":"could not fetch approved chaincode definition (name: '%s', sequence: '%d') on channel '%s'","messagePattern":"could not fetch approved chaincode definition \\(name: '(.+?)', sequence: '(.+?)'\\) on channel '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":582,"sourceCode":"\t\tprivateName := fmt.Sprintf(\"%s#%d\", ccname, nextSequence)\n\t\t_, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, privateName, orgState)\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithMessagef(err, \"could not deserialize namespace metadata for next sequence %d\", nextSequence)\n\t\t}\n\t\tif ok {\n\t\t\trequestedSequence = nextSequence\n\t\t}\n\t}\n\n\tlogger.Infof(\"Attempting to fetch approved definition (name: '%s', sequence: '%d') on channel '%s'\", ccname, requestedSequence, chname)\n\tprivateName := fmt.Sprintf(\"%s#%d\", ccname, requestedSequence)\n\tmetadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, privateName, orgState)\n\tif err != nil {\n\t\treturn nil, errors.WithMessagef(err, \"could not deserialize namespace metadata for %s\", privateName)\n\t}\n\n\tif !ok {\n\t\treturn nil, errors.Errorf(\"could not fetch approved chaincode definition (name: '%s', sequence: '%d') on channel '%s'\", ccname, requestedSequence, chname)\n\t}\n\n\treturn ef.fetchApprovedChaincodeDefinition(ccname, requestedSequence, metadata, orgState)\n}\n\n// QueryApprovedChaincodeDefinitions returns all approved chaincode definitions in Org state for the specified channel.\n// The return value is a map where the key is a combination of chaincode namespace and sequence number in the format \"<namespace>#<sequence_number>\",\n// and the value is the corresponding ApprovedChaincodeDefinition object.\nfunc (ef *ExternalFunctions) QueryApprovedChaincodeDefinitions(chname string, orgState ReadRangeableState) (map[string]*ApprovedChaincodeDefinition, error) {\n\t// Get all metadatas for the channel\n\tmetadatas, err := ef.Resources.Serializer.DeserializeAllMetadata(NamespacesName, orgState)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"could not fetch metadatas\")\n\t}\n\n\t// Get all approved chaincode definitions using the metadatas\n\tdefinitions := map[string]*ApprovedChaincodeDefinition{}\n\tfor privateName, metadata := range metadatas {","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L564-L600","documentation":"QueryApprovedChaincodeDefinition looked in the org's private (org-scoped) state for the approved definition at the requested name and sequence, and found no metadata entry — i.e., this org has not approved that chaincode at that sequence on that channel.","triggerScenarios":"Calling QueryApprovedChaincodeDefinition with a sequence the org never approved, a chaincode name typo, querying on a peer whose org has not approved, or querying before approval completed.","commonSituations":"Operators checking the wrong org's peer; querying with the wrong --sequence; race between approve transaction commit and the query; channel name mismatch.","solutions":["Confirm the sequence number matches what was approved (querycommitted / checkcommitreadiness)","Run the query on a peer belonging to the org that performed the approval","Verify chaincode name and channel name spelling; if not yet approved, run approveformyorg first"],"exampleFix":"// before\nqueryApproved(\"mycc\", seq=3) // org approved seq 2 only\n// after\nqueryApproved(\"mycc\", seq=2) // match the approved sequence","handlingStrategy":"validation","validationCode":"// Confirm this org approved the exact sequence before querying\napproved, err := orgApprovedSequences(ch, ccname) // from org private state / checkcommitreadiness\nif !contains(approved, requestedSequence) {\n    return fmt.Errorf(\"org has no approved definition for %s seq %d; run approveformyorg first\", ccname, requestedSequence)\n}","typeGuard":null,"tryCatchPattern":"def, err := ef.QueryApprovedChaincodeDefinition(ch, ccname, myOrg, seq)\nif err != nil && strings.Contains(err.Error(), \"could not fetch approved chaincode definition\") {\n    // run approveformyorg at that sequence, or correct the sequence/name\n}","preventionTips":["Query on a peer of the org that executed the approval","Wait for the approve transaction to commit before querying","Keep sequence numbers in shared deployment state to avoid mismatches"],"tags":["fabric","lifecycle","query"],"backgroundTag":"definition-not-approved","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"}