fix(clients): allow case-only email updates without duplicates (#6050)

Case-only email edits (test → Test) skipped the ClientRecord rename
because the gate used strings.EqualFold. SyncInbound then failed its
case-sensitive lookup and inserted a second row; the later fallback
rename hit UNIQUE constraint failed: clients.email.

Rename on any byte-level email difference so the same client is updated
in place.

Fixes #5951
This commit is contained in:
H-TTTTT
2026-07-21 21:50:50 +08:00
committed by GitHub
parent 11f602fe04
commit a0dec000b2
2 changed files with 33 additions and 1 deletions
+3 -1
View File
@@ -807,7 +807,9 @@ func (s *ClientService) UpdateInboundClient(inboundSvc *InboundService, data *mo
}
// Rename the client record in the same transaction as the settings JSON
// so no concurrent SyncInbound can see one renamed without the other.
if len(oldEmail) > 0 && !strings.EqualFold(oldEmail, clients[0].Email) {
// Byte-level compare (not EqualFold): case-only edits must rename too,
// otherwise SyncInbound's case-sensitive lookup creates a duplicate row.
if len(oldEmail) > 0 && oldEmail != clients[0].Email {
var renameTaken int64
if e := tx.Model(&model.ClientRecord{}).Where("email = ?", clients[0].Email).Count(&renameTaken).Error; e != nil {
return e