{"record":{"id":"e65e145839e1bbae","repo":"theonedev/onedev","slug":"no-commit-in-query-context","errorCode":null,"errorMessage":"No commit in query context","messagePattern":"No 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":155,"sourceCode":"\t\t} else if (operator == IssueQueryLexer.IsCurrent) {\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\treturn build.getProject().equals(issue.getProject()) && build.getId().toString().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No build in query context\"));\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 request.getTargetProject().equals(issue.getProject()) && request.getId().toString().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No pull request in query context\"));\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 commit.getProject().equals(issue.getProject()) && commit.getCommitId().name().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No commit in query context\"));\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\treturn build.getProject().equals(issue.getProject()) \n\t\t\t\t\t\t\t&& build.getStreamPreviousNumbers(Criteria.IN_CLAUSE_LIMIT)\n\t\t\t\t\t\t\t\t.stream()\n\t\t\t\t\t\t\t\t.anyMatch(it->it.equals(fieldValue));\n\t\t\t\t} else {\n\t\t\t\t\tthrow new ExplicitException(_T(\"No build 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 {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L137-L173","documentation":"When a CommitField criteria with 'is current' is evaluated via matches(), the engine fetches ProjectScopedCommit.get() from the context. If no commit is bound, an ExplicitException is thrown because the current commit is undefined.","triggerScenarios":"Evaluating an issue query with a CommitField 'is current commit' criteria outside a commit-scoped context — project issue list, REST call, background job.","commonSituations":"Commit-scoped saved queries reused elsewhere; CI scripts running issue queries without passing the checked-out commit; queries triggered from non-commit pages.","solutions":["Evaluate within a commit-bound context or bind ProjectScopedCommit before evaluation","Replace 'is current commit' with an explicit commit hash in the query","Catch ExplicitException and degrade gracefully (skip criteria or use default filter)","Check the calling integration passes the current commit into the query context"],"exampleFix":"// before\nIssueQuery query = IssueQuery.parse(\"\\\"Commit\\\" is current commit\");\nissues.stream().filter(query::matches); // throws without commit\n// after\nif (ProjectScopedCommit.get() == null) {\n    query = IssueQuery.parse(\"\\\"Commit\\\" is \"+commitId.name());\n}\nissues.stream().filter(query::matches);","handlingStrategy":"try-catch","validationCode":"if (ProjectScopedCommit.get() == null) { throw new IllegalStateException(\"'is current commit' criteria requires commit context\"); }","typeGuard":"boolean hasCommitContext() { return ProjectScopedCommit.get() != null; }","tryCatchPattern":"try { result = issues.stream().filter(query::matches).collect(toList()); } catch (ExplicitException e) { if (e.getMessage().contains(\"commit\")) { result = fallbackQuery(); } else { throw e; } }","preventionTips":["Check ProjectScopedCommit.get() before commit-dependent matching","Use explicit commit hashes outside commit-scoped pages","Pass the current commit into background evaluations","Test criteria in all execution contexts used in production"],"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"}