"500 Internal Server Error" when viewing list of pull requests in Bitbucket Data Center
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When viewing the list of pull requests in a repository, a 500 Internal Server Error is displayed.
Environment
This problem can occur in any version of Bitbucket Data Center.
Diagnosis
The <BitbucketHome>/log/atlassian-bitbucket.log
file shows this error:
Caused by: java.lang.IllegalStateException: Pull request author could not be found in its participants
at com.atlassian.stash.internal.pull.InternalPullRequest.getAuthor(InternalPullRequest.java:203)
at com.atlassian.bitbucket.rest.v2.api.pull.RestPullRequest.<init>(RestPullRequest.java:59)
Cause
This error occurs because at least one pull request doesn't have an author in the database. Under normal circumstances, this is unexpected, and the root cause remains unknown.
Solution
Ensure you have a working backup of your Bitbucket Data Center database.
Run the following query to determine which pull request is missing an author:
SELECT spr.id FROM sta_pull_request spr, repository r, project p WHERE spr.to_repository_id=r.id AND r.project_id=p.id and p.project_key='<proectKey>' AND r.slug='<repoSlug>' AND spr.id NOT IN (select pr_id from sta_pr_participant WHERE pr_role=0)
In the query, replace
<projectKey>
with the project key of the affected project.Replace
<repoSlug>
with the slug of the repository (this is the repository name in lower case, which you can see in the URL of the repository).The query should return the numeric ID of the pull request that is missing an author. If more than one ID is returned, contact Atlassian Support for assistance.
Since the pull request does not have an author, you can either:
Try to identify the most likely author using the audit logs of the repository (see View and configure the audit log, and search for
PullRequestOpenedEvent
), orPick a user who should be the pull request author yourself. Then use the following query to determine the numeric ID of the user, where
<username>
is the lowercase username of that user.select id from sta_normal_user WHERE slug='<username>'
Stop all Bitbucket Data Center nodes at this point so that modifications to the database can be made without interruption and risk of further corruption.
Run the following query and note the ID returned by it:
SELECT next_val FROM id_sequence WHERE sequence_name='sta_pr_participant';
Run the following query to increase the ID by one:
UPDATE id_sequence SET next_val = next_val + 1 WHERE sequence_name='sta_pr_participant';
Run the following query to add the author to the pull request:
INSERT INTO sta_pr_participant VALUES (<next_val>,<pr_id>,0,<user_id>,0,NULL);
Make the following replacements:
<next_val>
: The ID returned by the query in step 5<pr_id>
: The ID returned by the query in step 2<user_id>
: The ID returned by the query in step 3
Was this helpful?