theonedev/onedev · error · ExplicitException

No current pull request in query context

Error message

No current pull request in query context

What it means

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.

Source

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

			}
		} else if (operator == IssueQueryLexer.IsCurrent) {
			if (getFieldSpec() instanceof BuildChoiceField) {
				Build build = Build.get();
				if (build != null) { 
					return builder.and(
							builder.equal(projectAttribute, build.getProject()),
							builder.equal(valueAttribute, String.valueOf(build.getNumber())));
				} else {
					throw new ExplicitException(_T("No current build in query context"));
				}
			} else if (getFieldSpec() instanceof PullRequestChoiceField) {
				PullRequest request = PullRequest.get();
				if (request != null) {
					return builder.and(
							builder.equal(projectAttribute, request.getTargetProject()),
							builder.equal(valueAttribute, String.valueOf(request.getNumber())));
				} else {
					throw new ExplicitException(_T("No current pull request in query context"));
				}
			} else if (getFieldSpec() instanceof CommitField) {
				ProjectScopedCommit commit = ProjectScopedCommit.get();
				if (commit != null) {
					return builder.and(
							builder.equal(projectAttribute, commit.getProject()),
							builder.equal(valueAttribute, commit.getCommitId().name()));
				} else {
					throw new ExplicitException(_T("No current commit in query context"));
				}
			} else {
				throw new IllegalStateException();
			}
		} else if (operator == IssueQueryLexer.IsPrevious) {
			if (getFieldSpec() instanceof BuildChoiceField) {
				Build build = Build.get();
				if (build != null) { 
					Collection<Long> streamPreviousNumbers = Build.get().getStreamPreviousNumbers(Criteria.IN_CLAUSE_LIMIT);

View on GitHub (pinned to d44925c47c)

Solutions

  1. Run the query only from within a pull request's issue list where a current pull request is bound to the query context
  2. Remove the 'is current pull request' criteria and replace it with an explicit field value (e.g. 'Pull Request' is <number>)
  3. Wrap programmatic query execution in try/catch for ExplicitException and fall back to a context-free query
  4. Check that the code path sets the pull request in the query context (PullRequest.set or equivalent) before evaluating

Example fix

// before
IssueQuery query = IssueQuery.parse("\"Pull Request\" is current");
issueManager.query(project, query); // throws when not in PR context
// after
if (PullRequest.get() == null) {
    query = IssueQuery.parse("\"Pull Request\" is "+pr.getNumber());
}
issueManager.query(project, query);
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

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

Try / catch

try { issues = issueManager.query(project, query); } catch (ExplicitException e) { if (e.getMessage().contains("current pull request")) { issues = queryWithContextFreeAlternative(); } else { throw e; } }

Prevention

When it happens

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

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

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/47e938d1115b58f0. Report an issue: GitHub.