Skip to content

Bug 2089200 - Enforce unique nicknames with a UNIQUE index on profiles.nickname - #2815

Open
dklawren wants to merge 5 commits into
mozilla:masterfrom
dklawren:2089200
Open

dklawren wants to merge 5 commits into
mozilla:masterfrom
dklawren:2089200

Conversation

@dklawren

@dklawren dklawren commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Tests (all passing):

  1. New test t/bmo/user-nickname-unique.t: 9/9 pass, with no log noise.
  2. Upgrade from today's schema: I set up a DB the old way (NOT NULL DEFAULT '' with a plain index) and ran checksetup. The '' values became NULL, the existing nickname stayed, and MySQL now shows UNIQUE KEY profiles_nickname_idx. A second checksetup run changed nothing.
  3. Sanity suite plus extensions/Needinfo/t/mentions.t: 56 files, 17801 tests, all pass.

What changed (4 files):

  • Bugzilla/DB/Schema.pm: nickname can be NULL now, and its index is UNIQUE.
  • Bugzilla/Install/DB.pm: new _make_nicknames_unique(). It runs before _migrate_nicknames(), because that one saves users and would otherwise try to write NULL into a NOT NULL column. I also changed _migrate_nicknames() to look for nickname IS NULL instead of NOT nickname, which matched almost every nickname anyway.
  • Bugzilla/User.pm: users without a nickname now get NULL instead of ''. nick() still falls back to the part of the email before the @.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The nickname uniqueness constraint can abort upgrades when existing duplicates are present and cause uncaught duplicate-key errors during concurrent user saves.

2 open issues
What changed in this PR

This PR moves nickname uniqueness enforcement into the database, using NULL for users without a nickname so they can share a UNIQUE index.

Changes:

  • Make profiles.nickname nullable and its index unique.
  • Normalize empty nicknames before migrating nicknames from real names.
  • Update user nickname validation and generation to return undef when no nickname is available.
File Description
Bugzilla/​User.pm Represent missing or unavailable nicknames as undef.
Bugzilla/​Install/​DB.pm Convert empty nicknames to NULL and replace the index before nickname migration.
Bugzilla/​DB/​Schema.pm Define a nullable nickname column with a UNIQUE index.

Review effort: Balanced

Comment thread Bugzilla/DB/Schema.pm Resolved
Comment thread Bugzilla/Install/DB.pm Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The duplicate _update_nickname definition has an argument contract incompatible with its caller, causing saves to crash for existing nicknames, preventing nickname clearing, and omitting first-time assignments from the changes hash.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread Bugzilla/User.pm Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Profile cache eviction occurs before the outer transaction commits, allowing concurrent requests to repopulate stale profile data that remains cached after the save completes.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Evict the profile cache again after transaction commit

Bugzilla/​User.pm:289

The new outer transaction moves SUPER::update()'s memcached eviction before the actual commit; _claim_nickname() also evicts while this transaction is still open. A concurrent request can then reload the old committed profile into memcached after the last eviction, leaving stale nicknames and other profile fields cached after the save completes. Invalidate the profile cache again after this commit so the earlier evictions cannot leave that stale entry behind.

1 resolved since last review

Review effort: Balanced

@dklawren
dklawren requested review from Xzzz and cgsheeh November 7, 2026 01:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants