MySQL/MariaDB: Unique Constraint on Branches doesn't respect casing: UQE_branch_s #12050

Closed
opened 2025-11-02 09:56:11 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @sebastian-sauer on GitHub (Nov 20, 2023).

Description

In a repo with two branches feature/test_case and feature\Test_Case gitea throws a 500 exception when syncing branches as the unique constraint is violated.

SyncRepoBranches: Error 1062 (23000): Duplicate entry '<redacted_branch_name>' for key 'UQE_branch_s'

This error happened after an upgrade to 1.21.0 on an existing repo.

Workaround is to rename one of the branches.

Typically having this type of different branch names only based on casing is not needed (imho it's a bug ;) ) - but we shouldn't have a 500 page when accessing the repo.

Gitea Version

1.21.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Linux

How are you running Gitea?

Official binary

Database

MySQL/MariaDB

Originally created by @sebastian-sauer on GitHub (Nov 20, 2023). ### Description In a repo with two branches `feature/test_case` and `feature\Test_Case` gitea throws a 500 exception when syncing branches as the unique constraint is violated. `SyncRepoBranches: Error 1062 (23000): Duplicate entry '<redacted_branch_name>' for key 'UQE_branch_s'` This error happened after an upgrade to 1.21.0 on an existing repo. Workaround is to rename one of the branches. Typically having this type of different branch names only based on casing is not needed (imho it's a bug ;) ) - but we shouldn't have a 500 page when accessing the repo. ### Gitea Version 1.21.0 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System Linux ### How are you running Gitea? Official binary ### Database MySQL/MariaDB
GiteaMirror added the type/bugissue/workaround labels 2025-11-02 09:56:11 -06:00
Author
Owner

@yorliuk commented on GitHub (Nov 20, 2023):

I got the same error in Gitea log after updating to 1.21.
...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'

But I can't find such branch in DB.
mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

@yorliuk commented on GitHub (Nov 20, 2023): I got the same error in Gitea log after updating to 1.21. `...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'` But I can't find such branch in DB. `mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)`
Author
Owner

@silverwind commented on GitHub (Nov 20, 2023):

Related: https://github.com/go-gitea/gitea/issues/25909

@silverwind commented on GitHub (Nov 20, 2023): Related: https://github.com/go-gitea/gitea/issues/25909
Author
Owner

@sebastian-sauer commented on GitHub (Nov 20, 2023):

Are we "allowed" to remove a unique constraint in a patch release?

@sebastian-sauer commented on GitHub (Nov 20, 2023): Are we "allowed" to remove a unique constraint in a patch release?
Author
Owner

@yorliuk commented on GitHub (Nov 20, 2023):

I got the same error in Gitea log after updating to 1.21. ...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'

But I can't find such branch in DB. mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

It helped: https://github.com/go-gitea/gitea/issues/25909#issuecomment-1637254581

@yorliuk commented on GitHub (Nov 20, 2023): > I got the same error in Gitea log after updating to 1.21. `...dules/context/api.go:105:ServerError() [E] SyncRepoBranches: Error 1062 (23000): Duplicate entry '<BRANCH_NAME>' for key 'branch.UQE_branch_s'` > > But I can't find such branch in DB. `mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)` It helped: https://github.com/go-gitea/gitea/issues/25909#issuecomment-1637254581
Author
Owner

@silverwind commented on GitHub (Nov 20, 2023):

Are we "allowed" to remove a unique constraint in a patch release?

Anything reasonable is possible, but I think the solution is to make the field case-sensitive.

@silverwind commented on GitHub (Nov 20, 2023): > Are we "allowed" to remove a unique constraint in a patch release? Anything reasonable is possible, but I think the solution is to make the field case-sensitive.
Author
Owner

@wxiaoguang commented on GitHub (Dec 29, 2023):

For 1.21 (unlucky...) users, the workaround is to run the SQL manually:

ALTER TABLE branch MODIFY COLUMN `name` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL

It won't cause side-effect and won't conflict with the complete fix (if there is anything wrong, it could be revert to old COLLATE utf8mb4_general_ci)

@wxiaoguang commented on GitHub (Dec 29, 2023): For 1.21 (unlucky...) users, the workaround is to run the SQL manually: ``` ALTER TABLE branch MODIFY COLUMN `name` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL ``` It won't cause side-effect and won't conflict with the complete fix (if there is anything wrong, it could be revert to old `COLLATE utf8mb4_general_ci`)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12050