{"record":{"id":"460a034a250f1bac","repo":"theonedev/onedev","slug":"no-pull-request-in-query-context-460a03","errorCode":null,"errorMessage":"No pull request in query context","messagePattern":"No pull request in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/FixedInCurrentPullRequestCriteria.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.model.PullRequest;\nimport io.onedev.server.util.ProjectScope;\nimport io.onedev.server.util.criteria.Criteria;\n\npublic class FixedInCurrentPullRequestCriteria 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 (PullRequest.get() != null)\n\t\t\treturn new FixedInPullRequestCriteria(PullRequest.get()).getPredicate(projectScope, query, from, builder);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No pull request in query context\");\n\t}\n\n\t@Override\n\tpublic boolean matches(Issue issue) {\n\t\tif (PullRequest.get() != null)\n\t\t\treturn new FixedInPullRequestCriteria(PullRequest.get()).matches(issue);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No pull request in query context\");\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn IssueQuery.getRuleName(IssueQueryLexer.FixedInCurrentPullRequest);\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/FixedInCurrentPullRequestCriteria.java#L6-L41","documentation":"FixedInCurrentPullRequestCriteria.getPredicate() throws this ExplicitException when an issue query uses the '~Fixed in current pull request' rule but no pull request is bound to the query context. The criteria delegates to FixedInPullRequestCriteria with PullRequest.get(); when that is null, the query cannot be translated into a database predicate.","triggerScenarios":"Executing a DB-backed issue query containing FixedInCurrentPullRequest via getPredicate() when PullRequest.get() returns null.","commonSituations":"Applying a pull-request-scoped query (e.g. copied from a PR's issue list) on pages without a current PR; running such queries from scripts, REST API calls, or scheduled tasks where no PR context is established.","solutions":["Use this rule only in queries evaluated within a pull request context (PR detail / PR issue views).","Replace '~Fixed in current pull request' with an explicit '~Fixed in pull request(<number>)' criterion.","Establish the PullRequest context programmatically before evaluating the query if running in code.","Catch ExplicitException when parsing/executing queries and explain that the rule requires a pull request context."],"exampleFix":"// before\n\"~Fixed in current pull request\"\n// after\n\"~Fixed in pull request(42)\"","handlingStrategy":"try-catch","validationCode":"if (PullRequest.get() == null) {\n    throw new IllegalStateException(\"Query uses '~Fixed in current pull request' but no pull request context is active\");\n}","typeGuard":"boolean canEvaluateFixedInCurrentPullRequest() {\n    return PullRequest.get() != null;\n}","tryCatchPattern":"try {\n    Predicate p = criteria.getPredicate(projectScope, query, from, builder);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"No pull request in query context\")) {\n        // use a context-free alternative query or notify the user\n    } else {\n        throw e;\n    }\n}","preventionTips":["Restrict PR-relative queries to pull request scoped pages/jobs","Validate PullRequest.get() before executing queries containing current-PR rules","Prefer explicit '~Fixed in pull request(n)' criteria in saved queries","Handle ExplicitException centrally in query execution code"],"tags":["onedev","issue-query","query-context","pull-request"],"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"}