theonedev/onedev · warning · NotAcceptableException
Another pull request already opened for this change
Error message
Another pull request already opened for this change
What it means
OneDev's DefaultPullRequestService.open() refuses to create a pull request when an open pull request already exists for the same target<-source branch pair. findOpen() is consulted first; if it returns a live PR, a NotAcceptableException (HTTP 406) is thrown because duplicate PRs for the same change would fragment review and merge state.
Source
Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java:440
@Transactional
@Override
public void open(PullRequest request) {
Preconditions.checkArgument(request.isNew());
var target = Preconditions.checkNotNull(request.getTarget(),
"Pull request target must be set before calling open");
var source = Preconditions.checkNotNull(request.getSource(),
"Pull request source must be set before calling open");
Preconditions.checkNotNull(request.getSubmitter(),
"Pull request submitter must be set before calling open");
if (target.equals(source))
throw new NotAcceptableException("Source and target are the same");
PullRequest existing = findOpen(target, source);
if (existing != null)
throw new NotAcceptableException("Another pull request already opened for this change");
existing = findEffective(target, source);
if (existing != null) {
if (existing.isOpen())
throw new NotAcceptableException("Another pull request already opened for this change");
else
throw new NotAcceptableException("Another pull request already merged the change");
}
if (request.getBaseCommitHash() == null) {
ObjectId baseCommitId = gitService.getMergeBase(
target.getProject(), target.getObjectId(),
source.getProject(), source.getObjectId());
if (baseCommitId == null)
throw new NotAcceptableException("No common base for target and source");
request.setBaseCommitHash(baseCommitId.name());
}
View on GitHub (pinned to d44925c47c)
Solutions
- Check findOpen()/list the project's open pull requests before calling open() and reuse the existing PR instead
- Catch NotAcceptableException from open() and look up the existing PR to return its number/link to the user
- Make automated PR creation idempotent: key scripts on the target/source branch pair and skip creation if one exists
- If the existing PR is stale/wrong, close it first, then open the new one
Example fix
// before
pullRequestService.open(pullRequest); // throws if one already exists
// after
PullRequest existing = pullRequestService.findOpen(target, source);
if (existing == null)
pullRequestService.open(pullRequest);
else
logger.info("Reusing existing PR #{}", existing.getNumber()); Defensive patterns
Strategy: validation
Validate before calling
PullRequest existing = pullRequestService.findOpen(target, source);
if (existing != null)
return existing; // reuse instead of opening Try / catch
try {
pullRequestService.open(request);
} catch (NotAcceptableException e) {
if (e.getMessage().contains("Another pull request already opened")) {
PullRequest existing = pullRequestService.findOpen(target, source);
redirect(existing);
} else throw e;
} Prevention
- Always call findOpen()/findEffective before opening a PR
- Make automated PR creation idempotent per (target, source) pair
- Debounce double-submits in the UI
When it happens
Trigger: Calling PullRequestService.open() (directly or via the 'new pull request' flow) when findOpen(target, source) returns a non-null PullRequest, i.e. an open PR with the exact same target and source branches already exists.
Common situations: Double-submitting the PR creation form after a page reload; scripting PR creation in CI that runs on every push without checking for an existing PR; two users creating the same PR concurrently.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Reviewer not found:
- Pull request submitter cannot be reviewer
- Assignee not found:
- No permission to read code of source project:
- No permission to read code of target project:
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/62ba5a8417cad4e9.
Report an issue: GitHub.