{"record":{"id":"47e938d1115b58f0","repo":"theonedev/onedev","slug":"no-current-pull-request-in-query-context","errorCode":null,"errorMessage":"No current pull request in query context","messagePattern":"No current 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":81,"sourceCode":"\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 builder.and(\n\t\t\t\t\t\t\tbuilder.equal(projectAttribute, build.getProject()),\n\t\t\t\t\t\t\tbuilder.equal(valueAttribute, String.valueOf(build.getNumber())));\n\t\t\t\t} else {\n\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);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L63-L99","documentation":"In OneDev's issue query engine, the '~' style operator on a field whose value must come from the surrounding context (e.g. a PullRequestChoiceField) resolves the current pull request via PullRequest.get(). When the query is evaluated outside a pull-request context (no request bound to the current thread/context), an ExplicitException is thrown with this localized message because the criteria cannot be evaluated.","triggerScenarios":"Running an issue query containing a criteria that references 'current pull request' (operator IsCurrent/is current on a PullRequestChoiceField) from a context with no pull request set — e.g. from the global issue list, a saved query dashboard, a REST API call, or a scheduled job.","commonSituations":"A saved query written inside a pull request's issue list is reused elsewhere (project issue list, 'My issues' page); automation scripts querying issues with 'is current pull request' criteria; CI jobs evaluating queries without PR context.","solutions":["Run the query only from within a pull request's issue list where a current pull request is bound to the query context","Remove the 'is current pull request' criteria and replace it with an explicit field value (e.g. 'Pull Request' is <number>)","Wrap programmatic query execution in try/catch for ExplicitException and fall back to a context-free query","Check that the code path sets the pull request in the query context (PullRequest.set or equivalent) before evaluating"],"exampleFix":"// before\nIssueQuery query = IssueQuery.parse(\"\\\"Pull Request\\\" is current\");\nissueManager.query(project, query); // throws when not in PR context\n// after\nif (PullRequest.get() == null) {\n    query = IssueQuery.parse(\"\\\"Pull Request\\\" is \"+pr.getNumber());\n}\nissueManager.query(project, query);","handlingStrategy":"try-catch","validationCode":"if (PullRequest.get() == null) { throw new IllegalStateException(\"Query with 'is current pull request' requires PR context\"); }","typeGuard":"boolean hasPullRequestContext() { return PullRequest.get() != null; }","tryCatchPattern":"try { issues = issueManager.query(project, query); } catch (ExplicitException e) { if (e.getMessage().contains(\"current pull request\")) { issues = queryWithContextFreeAlternative(); } else { throw e; } }","preventionTips":["Check PullRequest.get() != null before running context-dependent queries","Prefer explicit PR-number criteria in saved/shared queries","Run context-dependent queries only from PR-scoped pages or integrations","Log query text with context availability to catch misconfigurations early"],"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-14T00:17:10.932Z"}