{"record":{"id":"f7f9796164fcf641","repo":"theonedev/onedev","slug":"no-pull-request-in-query-context","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/FieldOperatorCriteria.java","lineNumber":149,"sourceCode":"\t\t\t\t\treturn ((Collection) fieldValue).contains(userName);\n\t\t\t\telse \n\t\t\t\t\treturn Objects.equals(fieldValue, userName);\n\t\t\t} else {\n\t\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t\t\t}\n\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 {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L131-L167","documentation":"For a PullRequestChoiceField with the 'is current' operator, the matches() evaluation reads PullRequest.get() from the query context. Without a current pull request bound, an ExplicitException is thrown since there is nothing to compare the field value against.","triggerScenarios":"Running an in-memory matches() evaluation of a query containing a PullRequestChoiceField 'is current pull request' criteria outside any pull request context — global issue list, REST API, scheduled evaluation.","commonSituations":"Filters authored on a PR issue page reused from the project issue list; automation evaluating issue queries without PR context; webhook handlers running queries for events lacking PR scope.","solutions":["Run the query within a pull request context (PR issue list or code that sets PullRequest)","Replace 'is current pull request' with an explicit PR number criteria","Catch ExplicitException and fall back to an alternative query when no PR context exists","Ensure the calling integration binds the PR into the query context first"],"exampleFix":"// before\nIssueQuery query = IssueQuery.parse(\"\\\"Pull Request\\\" is current pull request\");\nissues.stream().filter(query::matches); // throws without PR\n// after\nPullRequest pr = PullRequest.get();\nIssueQuery query = IssueQuery.parse(\"\\\"Pull Request\\\" is \"+(pr!=null?\"current pull request\":pr.getNumber()));","handlingStrategy":"try-catch","validationCode":"if (PullRequest.get() == null) { throw new IllegalStateException(\"'is current pull request' criteria requires PR context\"); }","typeGuard":"boolean hasPullRequestContext() { return PullRequest.get() != null; }","tryCatchPattern":"try { result = issues.stream().filter(query::matches).collect(toList()); } catch (ExplicitException e) { if (e.getMessage().contains(\"pull request\")) { result = fallback(); } else { throw e; } }","preventionTips":["Verify PullRequest.get() before matching PR-dependent criteria","Prefer explicit PR numbers in saved filters","Run PR-dependent queries only in PR-scoped integrations","Bind the PR into context in webhook/event handlers before querying"],"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"}