theonedev/onedev · error · ExplicitException

No pull request in query context

Error message

No pull request in query context

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java:149

					return ((Collection) fieldValue).contains(userName);
				else 
					return Objects.equals(fieldValue, userName);
			} else {
				throw new NotAcceptableException(_T("Please login to perform this query"));
			}
		} else if (operator == IssueQueryLexer.IsCurrent) {
			if (getFieldSpec() instanceof BuildChoiceField) {
				Build build = Build.get();
				if (build != null) 
					return build.getProject().equals(issue.getProject()) && build.getId().toString().equals(fieldValue);
				else  
					throw new ExplicitException(_T("No build in query context"));
			} else if (getFieldSpec() instanceof PullRequestChoiceField) {
				PullRequest request = PullRequest.get();
				if (request != null) 
					return request.getTargetProject().equals(issue.getProject()) && request.getId().toString().equals(fieldValue);
				else  
					throw new ExplicitException(_T("No pull request in query context"));
			} else if (getFieldSpec() instanceof CommitField) {
				ProjectScopedCommit commit = ProjectScopedCommit.get();
				if (commit != null) 
					return commit.getProject().equals(issue.getProject()) && commit.getCommitId().name().equals(fieldValue);
				else  
					throw new ExplicitException(_T("No commit in query context"));
			} else {
				throw new IllegalStateException();
			}
		} else if (operator == IssueQueryLexer.IsPrevious) {
			if (getFieldSpec() instanceof BuildChoiceField) {
				Build build = Build.get();
				if (build != null) {
					return build.getProject().equals(issue.getProject()) 
							&& build.getStreamPreviousNumbers(Criteria.IN_CLAUSE_LIMIT)
								.stream()
								.anyMatch(it->it.equals(fieldValue));
				} else {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Run the query within a pull request context (PR issue list or code that sets PullRequest)
  2. Replace 'is current pull request' with an explicit PR number criteria
  3. Catch ExplicitException and fall back to an alternative query when no PR context exists
  4. Ensure the calling integration binds the PR into the query context first

Example fix

// before
IssueQuery query = IssueQuery.parse("\"Pull Request\" is current pull request");
issues.stream().filter(query::matches); // throws without PR
// after
PullRequest pr = PullRequest.get();
IssueQuery query = IssueQuery.parse("\"Pull Request\" is "+(pr!=null?"current pull request":pr.getNumber()));
Defensive patterns

Strategy: try-catch

Validate before calling

if (PullRequest.get() == null) { throw new IllegalStateException("'is current pull request' criteria requires PR context"); }

Type guard

boolean hasPullRequestContext() { return PullRequest.get() != null; }

Try / catch

try { result = issues.stream().filter(query::matches).collect(toList()); } catch (ExplicitException e) { if (e.getMessage().contains("pull request")) { result = fallback(); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/f7f9796164fcf641. Report an issue: GitHub.