{"record":{"id":"016f3d0d11c1e00b","repo":"theonedev/onedev","slug":"no-current-commit-in-query-context","errorCode":null,"errorMessage":"No current commit in query context","messagePattern":"No current commit in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java","lineNumber":90,"sourceCode":"\t\t\t\t\tthrow new ExplicitException(_T(\"No current build in query context\"));\n\t\t\t\t}\n\t\t\t} else if (getFieldSpec() instanceof PullRequestChoiceField) {\n\t\t\t\tPullRequest request = PullRequest.get();\n\t\t\t\tif (request != null) {\n\t\t\t\t\treturn builder.and(\n\t\t\t\t\t\t\tbuilder.equal(projectAttribute, request.getTargetProject()),\n\t\t\t\t\t\t\tbuilder.equal(valueAttribute, String.valueOf(request.getNumber())));\n\t\t\t\t} else {\n\t\t\t\t\tthrow new ExplicitException(_T(\"No current pull request in query context\"));\n\t\t\t\t}\n\t\t\t} else if (getFieldSpec() instanceof CommitField) {\n\t\t\t\tProjectScopedCommit commit = ProjectScopedCommit.get();\n\t\t\t\tif (commit != null) {\n\t\t\t\t\treturn builder.and(\n\t\t\t\t\t\t\tbuilder.equal(projectAttribute, commit.getProject()),\n\t\t\t\t\t\t\tbuilder.equal(valueAttribute, commit.getCommitId().name()));\n\t\t\t\t} else {\n\t\t\t\t\tthrow new ExplicitException(_T(\"No current commit in query context\"));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new IllegalStateException();\n\t\t\t}\n\t\t} else if (operator == IssueQueryLexer.IsPrevious) {\n\t\t\tif (getFieldSpec() instanceof BuildChoiceField) {\n\t\t\t\tBuild build = Build.get();\n\t\t\t\tif (build != null) { \n\t\t\t\t\tCollection<Long> streamPreviousNumbers = Build.get().getStreamPreviousNumbers(Criteria.IN_CLAUSE_LIMIT);\n\t\t\t\t\tif (!streamPreviousNumbers.isEmpty()) {\n\t\t\t\t\t\treturn builder.and(\n\t\t\t\t\t\t\t\tbuilder.equal(projectAttribute, build.getProject()),\n\t\t\t\t\t\t\t\tvalueAttribute.in(streamPreviousNumbers.stream().map(it->it.toString()).collect(Collectors.toSet())));\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn builder.disjunction();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new ExplicitException(_T(\"No current build in query context\"));","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L72-L108","documentation":"When an issue query criteria uses a CommitField with an operator whose value depends on the current commit, the engine looks up ProjectScopedCommit.get() from the evaluation context. If no commit is bound (query executed outside a commit-scoped context), an ExplicitException is thrown because the criteria value cannot be determined.","triggerScenarios":"Evaluating an issue query with a CommitField 'is current' style criteria while no ProjectScopedCommit is set in the current context — e.g. querying from the project issue list, REST API, or a build script where the commit context was never established.","commonSituations":"Saved queries referencing the current commit reused from a dashboard; CI pipelines executing issue queries without passing the checked-out commit; using the query in a context menu outside the commit page.","solutions":["Execute the query from a commit-scoped context (commit page or code path that sets ProjectScopedCommit)","Replace the 'is current commit' criteria with an explicit commit hash value in the query","Catch ExplicitException programmatically and degrade to a query without the commit criteria","Ensure the integration code binds ProjectScopedCommit before calling the query engine"],"exampleFix":"// before\nIssueQuery query = IssueQuery.parse(\"\\\"Commit\\\" is current\");\nissueManager.query(project, query); // throws outside commit context\n// after\nif (ProjectScopedCommit.get() == null) {\n    query = IssueQuery.parse(\"\\\"Commit\\\" is \"+commitId.name());\n}\nissueManager.query(project, query);","handlingStrategy":"try-catch","validationCode":"if (ProjectScopedCommit.get() == null) { throw new IllegalStateException(\"Query with 'is current commit' requires commit context\"); }","typeGuard":"boolean hasCommitContext() { return ProjectScopedCommit.get() != null; }","tryCatchPattern":"try { issues = issueManager.query(project, query); } catch (ExplicitException e) { if (e.getMessage().contains(\"current commit\")) { issues = fallbackQuery(); } else { throw e; } }","preventionTips":["Verify ProjectScopedCommit.get() before evaluating commit-dependent criteria","Use explicit commit hashes in saved queries","Pass the checked-out commit into any CI-side query evaluation","Test saved queries in all contexts where they will run"],"tags":["onedev","issue-query","query-context"],"backgroundTag":"missing-required-config","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}