theonedev/onedev · error · NotFoundException

Pull request not found:

Error message

Pull request not found: 

What it means

getPullRequest looks up the pull request by number via pullRequestService.find() after parsing the reference with PullRequestReference.of(). If no pull request with that number exists in the resolved project, it throws a JAX-RS NotFoundException (HTTP 404) naming the reference string.

Source

Thrown at server-core/src/main/java/io/onedev/server/ai/TodResource.java:1313

        var info = new CreatePullRequestEssentialInfo();
        info.currentProject = currentProject;
        info.target = target;
        info.source = source;
        info.submitter = user;

        return info;
    }    

    private PullRequest getPullRequest(Project currentProject, String referenceString) {
        var requestReference = PullRequestReference.of(referenceString, currentProject);
        var request = pullRequestService.find(requestReference.getProject(), requestReference.getNumber());
        if (request != null) {
            if (!SecurityUtils.canReadCode(request.getProject()))
                throw new UnauthorizedException("No permission to access pull request: " + referenceString);
            return request;
        } else {
            throw new NotFoundException("Pull request not found: " + referenceString);
        }
    }

    @SuppressWarnings("unchecked")
    @Path("/edit-pull-request")
    @POST
    public Map<String, Object> editPullRequest(
                @QueryParam("currentProject") @NotNull String currentProjectPath,
                @QueryParam("reference") @NotNull String pullRequestReference, @NotNull Map<String, Serializable> data) {
        var user = SecurityUtils.getUser();
        if (user == null)
            throw new UnauthenticatedException();

        var currentProject = getProject(currentProjectPath);

        var request = getPullRequest(currentProject, pullRequestReference);

        if (!SecurityUtils.canModifyPullRequest(request))

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the pull request number exists in the resolved project (list PRs in the UI).
  2. Use a fully-qualified reference ('project-path#number') to ensure the correct project is used.
  3. Check the PR wasn't removed; pick the correct reference from the current plan.

Example fix

// before
var ref = "#999"; // resolved in currentProject, doesn't exist
// after
var ref = "team-a/app#42"; // existing PR, explicit project
Defensive patterns

Strategy: validation

Validate before calling

var ref = PullRequestReference.of(referenceString, currentProject);
if (pullRequestService.find(ref.getProject(), ref.getNumber()) == null)
    throw new IllegalStateException("No pull request " + referenceString + " in " + ref.getProject().getPath());

Try / catch

try {
    var pr = callTodEndpoint(reference);
} catch (NotFoundException e) {
    if (e.getMessage().startsWith("Pull request not found")) {
        // re-resolve the PR number via the project's PR list
    } else throw e;
}

Prevention

When it happens

Trigger: Calling a TOD pull-request endpoint with a 'reference' whose number does not exist in the current (or explicitly named) project, e.g. 'team-a/app#999' when only #1..#50 exist.

Common situations: Wrong project in reference so number resolves against the wrong PR sequence; PR deleted; stale reference from an old AI plan; bare '#123' interpreted in currentProject where it doesn't exist.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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