{"record":{"id":"5da4036561941fc0","repo":"bytebase/bytebase","slug":"failed-to-get-statement-in-sheet-v","errorCode":null,"errorMessage":"failed to get statement in sheet %v","messagePattern":"failed to get statement in sheet (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/component/review/evaluator.go","lineNumber":718,"sourceCode":"\t}\n\n\tstatementSummaryResults := map[statementSummaryKey]*storepb.PlanCheckRunResult_Result{}\n\tif planCheckRun != nil {\n\t\tstatementSummaryResults = buildStatementSummaryResultMap(planCheckRun.Result.GetResults())\n\t}\n\n\t// A database group expands one sheet across every target, so classify each\n\t// (engine, sheet) once. Sheets run to common.MaxSheetCheckSize and this\n\t// path is synchronous on issue submission.\n\tstatementTypeCache := map[statementTypeKey][]storepb.StatementType{}\n\n\tvar celVarsList []map[string]any\n\tfor _, target := range targets {\n\t\ttaskStatement := \"\"\n\t\tif target.sheetSha256 != \"\" {\n\t\t\tsheet, err := stores.GetSheetFull(ctx, target.sheetSha256)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, approvalInputVersion, true, errors.Wrapf(err, \"failed to get statement in sheet %v\", target.sheetSha256)\n\t\t\t}\n\t\t\tif sheet == nil {\n\t\t\t\treturn nil, approvalInputVersion, true, errors.Errorf(\"sheet %v not found\", target.sheetSha256)\n\t\t\t}\n\t\t\ttaskStatement = sheet.Statement\n\t\t}\n\n\t\tenvironmentID := \"\"\n\t\tif target.database.EffectiveEnvironmentID != nil {\n\t\t\tenvironmentID = *target.database.EffectiveEnvironmentID\n\t\t}\n\n\t\t// Base CEL variables\n\t\tcelVars := map[string]any{\n\t\t\tcommon.CELAttributeResourceEnvironmentID: environmentID,\n\t\t\tcommon.CELAttributeResourceProjectID:     issue.ProjectID,\n\t\t\tcommon.CELAttributeResourceInstanceID:    target.database.InstanceID,\n\t\t\tcommon.CELAttributeResourceDatabaseName:  target.database.DatabaseName,","sourceCodeStart":700,"sourceCodeEnd":736,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/component/review/evaluator.go#L700-L736","documentation":"After unfolding targets, buildCELVariablesForDatabaseChange fetches the SQL statement text via stores.GetSheetFull(ctx, target.sheetSha256). If that store call returns an error (DB failure, sheet row unreadable), it wraps with 'failed to get statement in sheet <sha>'. This is a storage-layer failure retrieving the sheet that holds the task's statement.","triggerScenarios":"target.sheetSha256 is non-empty and stores.GetSheetFull returns a non-nil error: metadata database connection failure, corrupted sheet row, or transient query failure while loading the sheet by SHA-256.","commonSituations":"Metadata Postgres down or connection pool exhausted during plan check; sheet row deleted concurrently by cleanup while an old plan/issue still references its SHA; binary/schema drift in the sheet table after a version upgrade.","solutions":["Check the metadata database health (PG_URL reachable) and inspect the wrapped store error for the root cause.","Query the sheet table for the SHA printed in the message; if the row is missing, the plan's sheet reference is stale.","Re-create or re-upload the statement so a sheet with the referenced SHA exists, then retry.","If transient (timeout/deadlock), retry the plan check."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check sheet presence before evaluation:\nsheet, err := stores.GetSheetFull(ctx, sha)\nif err != nil || sheet == nil {\n  return fmt.Errorf(\"sheet %s unavailable: %v\", sha, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n  if isTransient(err) { // timeout/deadlock/connection\n    return retryWithBackoff(op)\n  }\n  return fmt.Errorf(\"failed to get statement in sheet %s: %w\", sha, err)\n}","preventionTips":["Monitor metadata database health; alert on connection pool saturation.","Keep sheet retention aligned with plan/issue lifetimes.","Retry transient store errors with backoff in the plan-check pipeline.","Log the sheet SHA in pipeline context for quick triage."],"tags":["database","sheet","storage"],"backgroundTag":"database-query-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}