theonedev/onedev · error · NotAcceptableException

Please login to perform this query

Error message

Please login to perform this query

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/codecomment/RepliedByMeCriteria.java:36

import io.onedev.server.util.ProjectScope;
import io.onedev.server.util.criteria.Criteria;

public class RepliedByMeCriteria extends Criteria<CodeComment> {

	private static final long serialVersionUID = 1L;

	@Override
	public Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<CodeComment, CodeComment> from, CriteriaBuilder builder) {
		if (User.get() != null) {
			Subquery<CodeCommentReply> replyQuery = query.subquery(CodeCommentReply.class);
			Root<CodeCommentReply> reply = replyQuery.from(CodeCommentReply.class);
			replyQuery.select(reply);
			replyQuery.where(builder.and(
					builder.equal(reply.get(CodeCommentReply.PROP_COMMENT), from),
					builder.equal(reply.get(CodeCommentReply.PROP_USER), User.get())));
			return builder.exists(replyQuery);
		} else {
			throw new NotAcceptableException(_T("Please login to perform this query"));
		}
	}

	@Override
	public boolean matches(CodeComment comment) {
		if (User.get() != null)
			return comment.getReplies().stream().anyMatch(it->it.getUser().equals(User.get()));
		else
			throw new NotAcceptableException(_T("Please login to perform this query"));
	}

	@Override
	public String toStringWithoutParens() {
		return CodeCommentQuery.getRuleName(CodeCommentQueryLexer.RepliedByMe);
	}

}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Log in / attach credentials so User.get() is populated before running the query.
  2. Run the query under a user context (impersonation or system user) in server-side jobs.
  3. Substitute '~replied by "user"~' with a concrete username for unauthenticated evaluation.
  4. Handle NotAcceptableException by returning 401 with a login hint.

Example fix

// before
List<CodeComment> comments = queryManager.findComments(project, "~replied by me~"); // anonymous

// after
if (User.get() == null)
    throw new NotAcceptableException("Login required for '~replied by me~' query");
List<CodeComment> comments = queryManager.findComments(project, "~replied by me~");
Defensive patterns

Strategy: validation

Validate before calling

if (User.get() == null) { /* redirect to login or use explicit username criteria */ }

Type guard

boolean authenticated() { return User.get() != null; }

Try / catch

try { comments = search(query); } catch (NotAcceptableException e) { log.warn("Query needs login: {}", e.getMessage()); }

Prevention

When it happens

Trigger: 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.

Common situations: API access without Authorization header/token; custom scripts or integrations invoking the query service before login; testing the query parser outside a web session.

Related errors


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