--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/AccountManager.java
@@ -127,6 +127,15 @@ public class AccountManager {
AccountExternalId.Key key = id(who);
AccountExternalId id = getAccountExternalId(db, key);
if (id == null) {
+ if (who.getUserName() != null) {
+ Account.Id ext = lookup("username:" + who.getUserName());
+ if (ext != null){
+ // An inconsistency is detected in the database, having a record for scheme "username:"
+ // but no record for scheme "gerrit:". Try to recover by linking
+ // "gerrit:" identity to the existing account.
+ return link(ext, who);
+ }
+ }
// New account, automatically create and return.
//
return create(db, who);
@@ -159,10 +168,10 @@ public class AccountManager {
}
}
}
- return null;
}
// We don't have at the moment an account_by_external_id cache
+ // or for whatever reason the account external id was not indexed
// but by using the accounts cache we get the list of external_ids
// without having to query the DB every time
if (key.getScheme().equals(AccountExternalId.SCHEME_GERRIT)