theonedev/onedev · error · ExplicitException

No issue in query context

Error message

No issue in query context

What it means

CurrentIssueCriteria.getPredicate() resolves the '~current issue~' operator to the issue bound to the current execution context via Issue.get(). OneDev sets this only in issue-scoped contexts (e.g. pages within an issue, pull request/build pipelines referencing an issue). With no current issue, it throws ExplicitException('No issue in query context').

Source

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

import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Predicate;

import io.onedev.commons.utils.ExplicitException;
import io.onedev.server.model.Issue;
import io.onedev.server.util.ProjectScope;
import io.onedev.server.util.criteria.Criteria;

public class CurrentIssueCriteria extends Criteria<Issue> {

	private static final long serialVersionUID = 1L;
	
	@Override
	public Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {
		if (Issue.get() != null)
			return builder.equal(from, Issue.get());
		else
			throw new ExplicitException("No issue in query context");
	}

	@Override
	public boolean matches(Issue issue) {
		if (Issue.get() != null)
			return Issue.get().equals(issue);
		else
			throw new ExplicitException("No issue in query context");
	}

	@Override
	public String toStringWithoutParens() {
		return IssueQuery.getRuleName(IssueQueryLexer.CurrentIssue);
	}

}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Only use '~current issue~' in contexts where an issue is active (issue page, linked build/PR context).
  2. Replace with the explicit issue number criteria (e.g. '~"number" is 123~') for general queries.
  3. Catch ExplicitException and degrade gracefully (skip criteria or notify the user).
  4. If embedding in dashboards, pass the issue via the appropriate context/impersonation API.

Example fix

// before
String query = "~current issue~"; // evaluated in global list -> throws

// after
String query = Issue.get() != null ? "~current issue~" : "~\"number\" is 123";
Defensive patterns

Strategy: try-catch

Validate before calling

if (Issue.get() == null) { /* use explicit issue number instead of '~current issue~' */ }

Type guard

Issue current = Issue.get(); boolean hasContext = current != null;

Try / catch

try { issues = queryManager.find(null, "~current issue~"); } catch (ExplicitException e) { issues = queryManager.find(null, "~\"number\" is " + fallbackNumber); }

Prevention

When it happens

Trigger: Running an issue query containing '~current issue~' in a context where no issue is associated: global issue list search, REST API call, scheduled job, or project-level board where Issue.get() is null.

Common situations: Using '~current issue~' in saved/global queries instead of only inside issue detail contexts; calling it from a build or PR script without issue linkage; testing queries from admin consoles.

Related errors


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