{"record":{"id":"38c3d3819e0e36d5","repo":"theonedev/onedev","slug":"no-project-in-query-context","errorCode":null,"errorMessage":"No project in query context","messagePattern":"No project in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/ProjectIsCurrentCriteria.java","lineNumber":25,"sourceCode":"import javax.persistence.criteria.JoinType;\nimport javax.persistence.criteria.Predicate;\n\nimport io.onedev.commons.utils.ExplicitException;\nimport io.onedev.server.model.Issue;\nimport io.onedev.server.model.Project;\nimport io.onedev.server.util.ProjectScope;\nimport io.onedev.server.util.criteria.Criteria;\n\npublic class ProjectIsCurrentCriteria extends Criteria<Issue> {\n\n\tprivate static final long serialVersionUID = 1L;\n\t\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {\n\t\tif (Project.get() != null) \n\t\t\treturn builder.equal(from.join(Issue.PROP_PROJECT, JoinType.INNER), Project.get());\n\t\telse\n\t\t\tthrow new ExplicitException(\"No project in query context\");\n\t}\n\n\t@Override\n\tpublic boolean matches(Issue issue) {\n\t\tif (Project.get() != null)\n\t\t\treturn Project.get().equals(issue.getProject());\n\t\telse\n\t\t\tthrow new ExplicitException(\"No project in query context\");\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn quote(Issue.NAME_PROJECT) + \" \"\n\t\t\t\t+ IssueQuery.getRuleName(IssueQueryLexer.IsCurrent);\n\t}\n\n}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/ProjectIsCurrentCriteria.java#L7-L43","documentation":"ProjectIsCurrentCriteria.getPredicate matches the pseudo-criterion 'project is current', comparing against Project.get(), the project bound to the current context. With no project in context it throws ExplicitException 'No project in query context' because the criterion cannot be evaluated.","triggerScenarios":"Running an issue query containing the 'is current' project criterion outside any project scope (Project.get() == null), e.g. global issue search or unscoped REST query.","commonSituations":"Saved queries containing 'project is current' reused from a global/dashboard context; API calls lacking the project path segment; embedded issue lists outside a project page.","solutions":["Run the query within a project scope (include project in URL/request).","Replace 'is current' in the query with an explicit 'project is <name>' criterion.","Bind Project context (Project.set) if executing programmatically.","Catch ExplicitException and fall back to a project-scoped query path."],"exampleFix":"// before\nquery: \"project is current\"  (run at global scope)\n// after\nquery: \"project is myproject\"","handlingStrategy":"validation","validationCode":"// Ensure project scope before running 'is current' queries\nif (Project.get() == null)\n    throw new ExplicitException(\"Query uses 'project is current'; run within a project scope\");","typeGuard":"Project current = Project.get();\nboolean projectScoped = current != null;","tryCatchPattern":"try {\n    Predicate p = criteria.getPredicate(projectScope, query, from, builder);\n} catch (ExplicitException e) {\n    throw new QueryContextException(e.getMessage());\n}","preventionTips":["Only expose 'is current' criteria in project-scoped query builders.","Substitute explicit project names in queries saved for global use.","Bind Project context when evaluating queries in services/tests."],"tags":["query-context","project-scope","issue-search"],"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-14T00:17:10.932Z"}