Page MenuHomePhabricator

Duplicate entry exception when editing label to duplicate name
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

If you try to edit an existing label and change its name to be the same as another one of your labels, you get an exception:

Error 1062: Duplicate entry '15233-New Label Adam 1' for key 'wll_user_name'
Function: MediaWiki\Watchlist\WatchlistLabelStore::save
Query: UPDATE `watchlist_label` SET wll_name = 'New Label Adam 1' WHERE wll_id = 118

Backtrace:

from /var/www/html/w/includes/libs/Rdbms/Database/Database.php(1226)
#0 /var/www/html/w/includes/libs/Rdbms/Database/Database.php(1210): Wikimedia\Rdbms\Database->getQueryException()
#1 /var/www/html/w/includes/libs/Rdbms/Database/Database.php(1184): Wikimedia\Rdbms\Database->getQueryExceptionAndLog()
#2 /var/www/html/w/includes/libs/Rdbms/Database/Database.php(641): Wikimedia\Rdbms\Database->reportQueryError()
#3 /var/www/html/w/includes/libs/Rdbms/Database/Database.php(1527): Wikimedia\Rdbms\Database->query()
#4 /var/www/html/w/includes/libs/Rdbms/Database/DBConnRef.php(127): Wikimedia\Rdbms\Database->update()
#5 /var/www/html/w/includes/libs/Rdbms/Database/DBConnRef.php(462): Wikimedia\Rdbms\DBConnRef->__call()
#6 /var/www/html/w/includes/libs/Rdbms/QueryBuilder/UpdateQueryBuilder.php(332): Wikimedia\Rdbms\DBConnRef->update()
#7 /var/www/html/w/includes/Watchlist/WatchlistLabelStore.php(34): Wikimedia\Rdbms\UpdateQueryBuilder->execute()
#8 /var/www/html/w/includes/Specials/SpecialWatchlistLabels.php(139): MediaWiki\Watchlist\WatchlistLabelStore->save()
#9 /var/www/html/w/includes/HTMLForm/HTMLForm.php(812): MediaWiki\Specials\SpecialWatchlistLabels->onSubmit()
#10 /var/www/html/w/includes/HTMLForm/HTMLForm.php(693): MediaWiki\HTMLForm\HTMLForm->trySubmit()
#11 /var/www/html/w/includes/HTMLForm/HTMLForm.php(709): MediaWiki\HTMLForm\HTMLForm->tryAuthorizedSubmit()
#12 /var/www/html/w/includes/Specials/SpecialWatchlistLabels.php(103): MediaWiki\HTMLForm\HTMLForm->show()
#13 /var/www/html/w/includes/Specials/SpecialWatchlistLabels.php(58): MediaWiki\Specials\SpecialWatchlistLabels->showForm()
#14 /var/www/html/w/includes/SpecialPage/SpecialPage.php(711): MediaWiki\Specials\SpecialWatchlistLabels->execute()
#15 /var/www/html/w/includes/SpecialPage/SpecialPageFactory.php(1743): MediaWiki\SpecialPage\SpecialPage->run()
#16 /var/www/html/w/includes/Actions/ActionEntryPoint.php(499): MediaWiki\SpecialPage\SpecialPageFactory->executePath()
#17 /var/www/html/w/includes/Actions/ActionEntryPoint.php(143): MediaWiki\Actions\ActionEntryPoint->performRequest()
#18 /var/www/html/w/includes/MediaWikiEntryPoint.php(184): MediaWiki\Actions\ActionEntryPoint->execute()
#19 /var/www/html/w/index.php(44): MediaWiki\MediaWikiEntryPoint->run()
#20 {main}
Steps to reproduce problem
  1. On any local test environment, add this to LocalSettings.php: $wgEnableWatchlistLabels = true;
  2. Login
  3. Create two labels by going to Special:WatchlistLabels/edit
  4. On Special:Watchlist, click on the edit icon next to one of your labels
  5. Change the name to be the same as the other label

Expected behaviour: Some sort of validation warning saying you cannot create a duplicate label
Observed behaviour: Exception above

Environment

Wiki(s): local docker MediaWiki 1.46.0-alpha (66c0066) 07:36, 25 November 2025.


Derived Requirement

Prevent users from editing an existing watchlist label to a name that already exists for that user. When a duplicate label name is entered, display a validation warning instead of causing a database exception.

Test Artifact(s):

Test Steps

Test Case 1: Prevent Duplicate Watchlist Label Names on Edit

  1. On a local test environment, add $wgEnableWatchlistLabels = true; to LocalSettings.php and reload the wiki.
  2. Login as any registered user.
  3. Navigate to Special:WatchlistLabels/edit and create two distinct labels.
  4. Navigate to Special:Watchlist and click the edit icon next to one of your labels.
  5. Attempt to change the label name to match the name of the other label.
  6. ✅❓❌⬜ AC1: Confirm that the system prevents the duplicate label name from being saved.
  7. ✅❓❌⬜ AC2: Confirm that a validation warning is displayed, informing the user that a label with that name already exists.

QA Results - Local

ACStatusDetails
1T411028#11434925
2T411028#11434925

Event Timeline

dom_walden renamed this task from Exceptions/warnings when trying to create/edit a label with a duplicate name to Duplicate entry exception when editing label to duplicate name.Nov 25 2025, 3:26 PM
dom_walden updated the task description. (Show Details)

Change #1212531 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/core@master] Watchlist labels: Add error when saving a duplicate name

https://gerrit.wikimedia.org/r/1212531

Change #1212531 merged by jenkins-bot:

[mediawiki/core@master] Watchlist labels: Add error when saving a duplicate name

https://gerrit.wikimedia.org/r/1212531

@Samwilson Confirmed duplicate entry exception when editing label to duplicate name, as seen in the video below. I will mark this as Resolved. Thanks for all your work!

Test Result - Local

Status: ✅ PASS
Environment: Local: MediaWiki 1.46.0-alpha (5061777) 19:37, 4 December 2025
OS: macOS Tahoe 26.1
Browser: Chrome 142
Device: MBA
Emulated Device: NA

Test Artifact(s):

Test Steps

Test Case 1: Prevent Duplicate Watchlist Label Names on Edit

  1. On a local test environment, add $wgEnableWatchlistLabels = true; to LocalSettings.php and reload the wiki.
  2. Login as any registered user.
  3. Navigate to Special:WatchlistLabels/edit and create two distinct labels.
  4. Navigate to Special:Watchlist and click the edit icon next to one of your labels.
  5. Attempt to change the label name to match the name of the other label.
  6. AC1: Confirm that the system prevents the duplicate label name from being saved.

  1. AC2: Confirm that a validation warning is displayed, informing the user that a label with that name already exists.

See AC1

GMikesell-WMF updated the task description. (Show Details)
GMikesell-WMF updated Other Assignee, removed: GMikesell-WMF.
GMikesell-WMF updated the task description. (Show Details)