{"record":{"id":"4f86cf85d7555382","repo":"theonedev/onedev","slug":"no-commit-id-in-query-context","errorCode":null,"errorMessage":"No commit id in query context","messagePattern":"No commit id in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/FixedInCurrentCommitCriteria.java","lineNumber":24,"sourceCode":"import javax.persistence.criteria.From;\nimport javax.persistence.criteria.Predicate;\n\nimport io.onedev.commons.utils.ExplicitException;\nimport io.onedev.server.model.Issue;\nimport io.onedev.server.util.ProjectScope;\nimport io.onedev.server.util.ProjectScopedCommit;\nimport io.onedev.server.util.criteria.Criteria;\n\npublic class FixedInCurrentCommitCriteria extends Criteria<Issue> {\n\n\tprivate static final long serialVersionUID = 1L;\n\t\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {\n\t\tif (ProjectScopedCommit.get() != null)\n\t\t\treturn new FixedInCommitCriteria(ProjectScopedCommit.get()).getPredicate(projectScope, query, from, builder);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No commit id in query context\");\n\t}\n\n\t@Override\n\tpublic boolean matches(Issue issue) {\n\t\tif (ProjectScopedCommit.get() != null)\n\t\t\treturn new FixedInCommitCriteria(ProjectScopedCommit.get()).matches(issue);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No commit in query context\");\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn IssueQuery.getRuleName(IssueQueryLexer.FixedInCurrentCommit);\n\t}\n\n}\n","sourceCodeStart":6,"sourceCodeEnd":41,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedInCurrentCommitCriteria.java#L6-L41","documentation":"FixedInCurrentCommitCriteria.getPredicate() throws this ExplicitException when the query uses the '~Fixed in current commit' rule but no commit is bound to the query context. It delegates to FixedInCommitCriteria using ProjectScopedCommit.get(); when that context holder is null, the query cannot be translated to a database predicate and the error is thrown.","triggerScenarios":"Running an issue query containing FixedInCurrentCommit and calling getPredicate() (the DB-backed query path) when ProjectScopedCommit.get() returns null.","commonSituations":"Using a commit-scoped issue query on pages that list issues without a current commit (global issue list, dashboards, REST API queries); copying a query from a commit detail page elsewhere.","solutions":["Evaluate this query only where a current commit exists (commit detail page, commit-scoped issue views).","Rewrite the query to use '~Fixed in commit(<hash>)' or a build/branch-based criterion instead of the current-commit rule.","If calling programmatically, populate the ProjectScopedCommit context before executing the query.","Catch ExplicitException during query construction and report that the rule requires a commit context."],"exampleFix":"// before\n\"~Fixed in current commit\" // evaluated outside commit context\n// after\n\"~Fixed in commit(1a2b3c4)\"","handlingStrategy":"try-catch","validationCode":"if (ProjectScopedCommit.get() == null) {\n    throw new IllegalStateException(\"Query uses '~Fixed in current commit' but no commit context is active\");\n}","typeGuard":"boolean canEvaluateFixedInCurrentCommit() {\n    return ProjectScopedCommit.get() != null;\n}","tryCatchPattern":"try {\n    Predicate p = criteria.getPredicate(projectScope, query, from, builder);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"No commit id in query context\")) {\n        // fall back to a context-free query or report to the caller\n    } else {\n        throw e;\n    }\n}","preventionTips":["Only attach commit-relative queries to commit-scoped UI or jobs","Check ProjectScopedCommit.get() before running queries with context-relative rules","Rewrite shared queries to reference explicit commit hashes","Catch ExplicitException at the query-execution boundary"],"tags":["onedev","issue-query","query-context","commit"],"backgroundTag":"missing-query-context","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"}