incubator-devlake icon indicating copy to clipboard operation
incubator-devlake copied to clipboard

[Bug][org] User/account linking compares emails case-sensitively and silently drops matches

Open vbhanuchander-lang opened this issue 3 months ago • 0 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

What happened

ConnectUserAccountsExact links users to accounts by exact map lookup, so the email comparison is case-sensitive. A user imported from users.csv with the address [email protected] is not linked to an account whose email is [email protected], and the account is silently left unlinked.

In backend/plugins/org/tasks/user_account.go the map is keyed on the raw address (line 49):

emails[user.Email] = user.Id

and looked up with the raw account address (line 79):

if userId, ok := emails[account.Email]; account.Email != "" && ok {

Email addresses are treated case-insensitively in practice, and the two sides of this comparison come from different systems: a corporate git config, a provider profile, and a hand-maintained CSV routinely disagree on capitalisation of the same address. When they do, the link is dropped with no warning — the subtask reports success and the account simply never appears in user_accounts.

The consequence is not cosmetic. Once an account is unlinked, everything that attributes through it stops being counted for that user, so the account's activity is missing from work logs and from any team-level metric built on user_accounts.

There is also no second chance: the scan is restricted to id NOT IN (SELECT account_id FROM user_accounts) (line 58), so a later run will not revisit an account that failed to match, and the name-based fallbacks (lines 87 and 95) only help when the display name or login happens to equal the user's name exactly.

What do you expect to happen

Two addresses that differ only in capitalisation should be treated as the same address and linked.

How to reproduce

  1. Import a user via PUT /plugins/org/users.csv whose email is E6 (any mixed case value).
  2. Have an account whose email is e6, with a name and login that do not match the user's name.
  3. Run the connectUserAccountsExact subtask.
  4. No user_accounts row is created for that account.

I added exactly this case to the existing org e2e fixtures; it fails before the change and passes after.

Anything else

Found while investigating #8698, where a reporter's GitHub account was never linked and only commit activities appeared in work logs. Case sensitivity is not the cause of that issue — I posted the root cause there separately — but it is the same class of silent linkage failure and it turned up while reading this code.

Version

main

Are you willing to submit PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

vbhanuchander-lang avatar Aug 13 '26 11:08 vbhanuchander-lang