Modification of repository labels produces a database error message in Bitbucket

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

Selecting a label or modifying an existing label can cause an error message "A database error has occurred".

Environment

6.10.0+

Diagnosis

You can see any one of the below errors in the atlssian-bitbucket.log

Case 1:

If this is the case, you can see multiple labels with the same name and when you are trying to select one of them, you can see the below error:

1 2 3 4 2021-05-06 14:06:56,454 DEBUG [https-jsse-nio-8443-exec-2] user @1R5NFHEx846x94752x0 1j6z11n 10.2.146.99 "POST /rest/api/latest/projects/<proj_key>/repos/<repo_slug>/labels HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping ServiceException to REST response 500 com.atlassian.bitbucket.DataStoreException: A database error has occurred. .. Caused by: org.hibernate.NonUniqueResultException: query did not return a unique result: 6

Case 2:

In this case, there will be no duplicate labels and when you try to delete/modify a label, you can see the below error:

1 2 3 4 5 2021-11-17 15:06:15,043 DEBUG [http-nio-7990-exec-70] user *1X8W6DVx906x4137511x14 1jjoc9z 165.225.93.26 "DELETE /rest/api/latest/projects/<proj_key>/repos/<repo_slug>/labels/<label_name> HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping ServiceException to REST response 500 com.atlassian.bitbucket.DataStoreException: A database error has occurred. .. Caused by: org.hibernate.NonUniqueResultException: query did not return a unique result: 5

Cause

For case 1:

There is no unique constraint on the bb_label.name table, which causes the issue.

For case 2:

There are no unique constraints on the table bb_label_mapping. This could cause duplicates in the table with same label_id, labelable_id and labelable_type.

Solution

Until the bugs are fixed, you will need to manually delete the duplicate records to get rid of the error.

Please make sure to take a backup of your database before performing any DML operations on it. 

Run the below two queries in your Bitbucket database and reach out to Bitbucket support team for further instructions to safely remove the duplicates.

1 2 select * from bb_label_mapping; select * from bb_label;

Updated on March 21, 2025

Still need help?

The Atlassian Community is here for you.