{"record":{"id":"77c5ebe72a530314","repo":"theonedev/onedev","slug":"please-login-to-perform-this-query-77c5eb","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/codecomment/RepliedByMeCriteria.java","lineNumber":36,"sourceCode":"import io.onedev.server.util.ProjectScope;\nimport io.onedev.server.util.criteria.Criteria;\n\npublic class RepliedByMeCriteria extends Criteria<CodeComment> {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<CodeComment, CodeComment> from, CriteriaBuilder builder) {\n\t\tif (User.get() != null) {\n\t\t\tSubquery<CodeCommentReply> replyQuery = query.subquery(CodeCommentReply.class);\n\t\t\tRoot<CodeCommentReply> reply = replyQuery.from(CodeCommentReply.class);\n\t\t\treplyQuery.select(reply);\n\t\t\treplyQuery.where(builder.and(\n\t\t\t\t\tbuilder.equal(reply.get(CodeCommentReply.PROP_COMMENT), from),\n\t\t\t\t\tbuilder.equal(reply.get(CodeCommentReply.PROP_USER), User.get())));\n\t\t\treturn builder.exists(replyQuery);\n\t\t} else {\n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean matches(CodeComment comment) {\n\t\tif (User.get() != null)\n\t\t\treturn comment.getReplies().stream().anyMatch(it->it.getUser().equals(User.get()));\n\t\telse\n\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn CodeCommentQuery.getRuleName(CodeCommentQueryLexer.RepliedByMe);\n\t}\n\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/codecomment/RepliedByMeCriteria.java#L18-L54","documentation":"RepliedByMeCriteria.getPredicate() translates a '~replied by me~' code comment query into a JPA EXISTS subquery compared against the current user. Because 'me' is user-relative, it throws NotAcceptableException('Please login to perform this query') when User.get() is null, i.e. no authenticated user is bound to the thread.","triggerScenarios":"Running a code comment query containing the RepliedByMe operator through a persistence-backed search (getPredicate path) with an anonymous/unauthenticated context: unauthenticated REST call, background job, or service call without user context.","commonSituations":"API access without Authorization header/token; custom scripts or integrations invoking the query service before login; testing the query parser outside a web session.","solutions":["Log in / attach credentials so User.get() is populated before running the query.","Run the query under a user context (impersonation or system user) in server-side jobs.","Substitute '~replied by \"user\"~' with a concrete username for unauthenticated evaluation.","Handle NotAcceptableException by returning 401 with a login hint."],"exampleFix":"// before\nList<CodeComment> comments = queryManager.findComments(project, \"~replied by me~\"); // anonymous\n\n// after\nif (User.get() == null)\n    throw new NotAcceptableException(\"Login required for '~replied by me~' query\");\nList<CodeComment> comments = queryManager.findComments(project, \"~replied by me~\");","handlingStrategy":"validation","validationCode":"if (User.get() == null) { /* redirect to login or use explicit username criteria */ }","typeGuard":"boolean authenticated() { return User.get() != null; }","tryCatchPattern":"try { comments = search(query); } catch (NotAcceptableException e) { log.warn(\"Query needs login: {}\", e.getMessage()); }","preventionTips":["Wrap background query execution in a user context","Prefer '~replied by \"user\"~' in service-account queries","Return 401 early when credentials are absent"],"tags":["authentication","onedev","jpa-query"],"backgroundTag":"authentication-required","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"}