{"record":{"id":"19a9f399eaa035d4","repo":"theonedev/onedev","slug":"please-login-to-perform-this-query-19a9f3","errorCode":null,"errorMessage":"Please login to perform this query","messagePattern":"Please login to perform this query","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/WatchedByMeCriteria.java","lineNumber":29,"sourceCode":"import org.jspecify.annotations.Nullable;\n\nimport io.onedev.server.exception.NotAcceptableException;\nimport io.onedev.server.model.Issue;\nimport io.onedev.server.model.User;\nimport io.onedev.server.util.ProjectScope;\nimport io.onedev.server.util.criteria.Criteria;\n\npublic class WatchedByMeCriteria extends Criteria<Issue> {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {\n\t\tvar user = User.get();\n\t\tif (user != null) \n\t\t\treturn getCriteria(user).getPredicate(projectScope, query, from, builder);\n\t\telse \n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t}\n\n\t@Override\n\tpublic boolean matches(Issue issue) {\n\t\tvar user = User.get();\n\t\tif (user != null)\n\t\t\treturn getCriteria(user).matches(issue);\n\t\telse\n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t}\n\t\n\tprivate Criteria<Issue> getCriteria(User user) {\n\t\treturn new WatchedByUserCriteria(user);\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn IssueQuery.getRuleName(WatchedByMe);","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/WatchedByMeCriteria.java#L11-L47","documentation":"OneDev's WatchedByMeCriteria resolves the issue watch list of the 'current user' at query build time via User.get(). When no user is bound to the current request/session (anonymous context), the criteria cannot evaluate, so it throws NotAcceptableException with 'Please login to perform this query'. This is a guard against using self-referencing query criteria without an authenticated identity.","triggerScenarios":"Executing an issue query containing the 'watched by me' criteria (e.g. REST/GraphQL query endpoint or saved query evaluation) while the HTTP request has no authenticated session — anonymous access, expired session, or calling query evaluation from a non-web thread without a User bound.","commonSituations":"Users whose login session expired then retry a saved issue query; API clients calling issue query endpoints without an auth token; scripts using OneDev REST API anonymously; jobs executing queries in background threads without user context.","solutions":["Log in (or supply an Authorization token / session cookie) before running the query","Replace 'watched by me' with an explicit user criteria such as 'watched by <user>' so no current-user context is needed","For API/automation, configure a personal access token for the client and pass it on every request","If triggered in a background thread, run the query in a user context (e.g. with User set via the appropriate context holder)"],"exampleFix":"// before (anonymous REST call)\ncurl http://onedev/api/query/issues?query=\"watched by me\"\n// after\ncurl -H \"Authorization: Bearer <token>\" 'http://onedev/api/query/issues?query=watched%20by%20me'","handlingStrategy":"type-guard","validationCode":"if (OneDevCurrentUser.get() == null) { throw new AuthRequiredError(\"login required for 'watched by me' query\"); }","typeGuard":"function hasUser(): boolean { return io.onedev.server.model.User.get() != null; }","tryCatchPattern":"try { runIssueQuery(query); } catch (NotAcceptableException e) { if (e.getMessage().contains(\"Please login\")) { reauthenticate(); retryQuery(); } else { throw e; } }","preventionTips":["Check authentication state before issuing user-relative queries","Use explicit user criteria ('watched by <user>') in automation","Attach API tokens to all REST calls","Avoid evaluating saved queries in threads without a user context"],"tags":["authentication","query","onedev"],"backgroundTag":"authentication-required","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"}