{"record":{"id":"3fe04a7acc64cfcb","repo":"theonedev/onedev","slug":"no-current-build-in-query-context","errorCode":null,"errorMessage":"No current build in query context","messagePattern":"No current build 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":72,"sourceCode":"\t\t\tif (User.get() != null) \n\t\t\t\treturn builder.equal(valueAttribute, User.get().getName());\n\t\t\telse \n\t\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t\t} else if (operator == IssueQueryLexer.IsNotMe) {\n\t\t\tif (User.get() != null) {\n\t\t\t\treturn builder.not(builder.equal(valueAttribute, User.get().getName()));\n\t\t\t} else {\n\t\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\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\"));","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L54-L90","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the query only within a build-bound context (build pipeline, build page).","Replace '~is current~' with the concrete build number ('~is \"42\"~') for general contexts.","For non-build fields check the field spec — 'is current' also supports pull-request fields via PullRequest.get(); ensure the right context exists.","Catch ExplicitException and skip the criteria or return a clear user-facing message."],"exampleFix":"// before\nString query = \"~fixed in build is current~\"; // no build context -> throws\n\n// after\nBuild build = Build.get();\nString query = build != null\n    ? \"~fixed in build is current~\"\n    : \"~fixed in build is \\\"42\\\"~\";","handlingStrategy":"try-catch","validationCode":"if (Build.get() == null) { /* fall back to explicit build number */ }","typeGuard":"Build build = Build.get(); boolean hasBuildContext = build != null;","tryCatchPattern":"try { issues = queryManager.find(null, \"~fixed in build is current~\"); } catch (ExplicitException e) { issues = queryManager.find(null, \"~fixed in build is \\\"42\\\"~\"); }","preventionTips":["Only use '~is current~' inside build- or PR-bound contexts","Use explicit build numbers in saved/global queries","Catch ExplicitException to provide contextual fallbacks"],"tags":["onedev","query-context","build"],"backgroundTag":"missing-required-context","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}