theonedev/onedev · error · ExplicitException

No current build in query context

Error message

No current build in query context

What it means

FieldOperatorCriteria.getValuePredicate() resolves '~is current~' for build-choice fields by reading the build bound to the current context via Build.get(). In contexts with no associated build (global searches, REST calls, schedules) it throws ExplicitException('No current build in query context').

Source

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

			if (User.get() != null) 
				return builder.equal(valueAttribute, User.get().getName());
			else 
				throw new NotAcceptableException(_T("Please login to perform this query"));
		} else if (operator == IssueQueryLexer.IsNotMe) {
			if (User.get() != null) {
				return builder.not(builder.equal(valueAttribute, User.get().getName()));
			} 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 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"));

View on GitHub (pinned to d44925c47c)

Solutions

  1. Run the query only within a build-bound context (build pipeline, build page).
  2. Replace '~is current~' with the concrete build number ('~is "42"~') for general contexts.
  3. For non-build fields check the field spec — 'is current' also supports pull-request fields via PullRequest.get(); ensure the right context exists.
  4. Catch ExplicitException and skip the criteria or return a clear user-facing message.

Example fix

// before
String query = "~fixed in build is current~"; // no build context -> throws

// after
Build build = Build.get();
String query = build != null
    ? "~fixed in build is current~"
    : "~fixed in build is \"42\"~";
Defensive patterns

Strategy: try-catch

Validate before calling

if (Build.get() == null) { /* fall back to explicit build number */ }

Type guard

Build build = Build.get(); boolean hasBuildContext = build != null;

Try / catch

try { issues = queryManager.find(null, "~fixed in build is current~"); } catch (ExplicitException e) { issues = queryManager.find(null, "~fixed in build is \"42\"~"); }

Prevention

When it happens

Trigger: Executing an issue query with '~<build field> is current~' where no build is active: project-wide issue search, API invocation, cron/report jobs, or fields that are not BuildChoiceField/PullRequestChoiceField contexts.

Common situations: Saved queries using 'is current' run from CI dashboards outside a build; anonymous API calls; queries evaluated during issue bulk operations with no build context.

Related errors


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