{"record":{"id":"d602e117d87fae6b","repo":"apache/druid","slug":"query-s-was-not-found-the-query-details-are-no","errorCode":null,"errorMessage":"Query [%s] was not found. The query details are no longer present or might not be of the type [%s]. Verify that the id is correct.","messagePattern":"Query \\[(.+?)\\] was not found\\. The query details are no longer present or might not be of the type \\[(.+?)\\]\\. Verify that the id is correct\\.","errorType":"http","errorClass":"DruidException","httpStatus":404,"severity":"error","filePath":"multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java","lineNumber":300,"sourceCode":"      @Context final HttpServletRequest req\n  )\n  {\n    try {\n      AuthorizationUtils.setRequestAuthorizationAttributeIfNeeded(req);\n      final AuthenticationResult authenticationResult = AuthorizationUtils.authenticationResultFromRequest(req);\n\n      Optional<SqlStatementResult> sqlStatementResult = getStatementStatus(\n          queryId,\n          authenticationResult,\n          true,\n          Action.READ,\n          detail\n      );\n\n      if (sqlStatementResult.isPresent()) {\n        return Response.ok().entity(sqlStatementResult.get()).build();\n      } else {\n        throw queryNotFoundException(queryId);\n      }\n    }\n    catch (DruidException e) {\n      return buildNonOkResponse(e);\n    }\n    catch (ForbiddenException e) {\n      log.debug(\"Got forbidden request for reason [%s]\", e.getErrorMessage());\n      return buildNonOkResponse(Forbidden.exception());\n    }\n    catch (Exception e) {\n      log.warn(e, \"Failed to handle query [%s]\", queryId);\n      return buildNonOkResponse(DruidException.forPersona(DruidException.Persona.DEVELOPER)\n                                              .ofCategory(DruidException.Category.UNCATEGORIZED)\n                                              .build(e, \"Failed to handle query [%s]\", queryId));\n    }\n  }\n\n  @GET","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java#L282-L318","documentation":"The /sql/statements/{id} status endpoint could not find a live MSQ query detail for the given query id. SqlStatementResource.doGetStatus throws a user-facing NotFoundException (queryNotFoundException) explaining that details expired, the query finished and was cleaned up, or the id belongs to a different engine/type. The HTTP response carries this DruidException.","triggerScenarios":"GET /druid/v2/sql/statements/{queryId} where the id was never issued, the MSQ query completed and its details were auto-deleted (per idle timeout / durable storage cleanup), or the id refers to a native/non-MSQ query.","commonSituations":"Client polling a finished query after retention elapsed; using a native query id with the SQL statements API; typo'd or truncated query id; cluster restarted losing in-memory details when durable storage is not configured.","solutions":["Verify the queryId against the id returned by the original POST /druid/v2/sql/statements response.","Enable durable storage so details survive and are retrievable past worker cleanup.","Poll promptly while the query is running; once complete, consume results (and status) before the idle/retention timeout deletes them."],"exampleFix":"// before\nGET /druid/v2/sql/statements/query-abc // hours after completion, details purged\n// after\n// fetch the id from the POST response and poll within the retention window\nString id = postResponse.getHeader(\"X-Druid-Query-Id\");\nGET /druid/v2/sql/statements/ + id","handlingStrategy":"validation","validationCode":"// keep the id returned by the POST and poll within the retention window\nfinal String id = postResponse.getHeader(\"X-Druid-Query-Id\");\nif (id == null || id.isBlank()) {\n  throw new IllegalStateException(\"no query id captured; cannot poll status\");\n}","typeGuard":null,"tryCatchPattern":"Response resp = target.path(\"druid/v2/sql/statements/\" + queryId).request().get();\nif (resp.getStatus() == 404) {\n  // details expired or wrong id — re-fetch results or resubmit\n}","preventionTips":["Persist the queryId from the POST response before polling","Enable durable storage so details survive completion and restarts","Consume results/status before the idle timeout purges them","Use the SQL statements API only for MSQ query ids"],"tags":["msq","rest-api","not-found","query-status"],"backgroundTag":"record-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}