Page MenuHomePhabricator

Actor migration seems to have broken deleteDefaultMessages.php, and by extension the update process for really old wikis
Closed, ResolvedPublic

Description

deleteDefaultMessages.php doesn't seem to work, because it tries to add the bot group to the user "MediaWiki default".

Instead of being a system user, "MediaWiki default" seems to be an anon actor, so you can't add groups to it. And you can change to User::newSystemUser because than there is a duplicate key in actor table.

Complaint originally at: https://www.mediawiki.org/w/index.php?title=Topic:V9jdyxvfc2xxlnts


Steps to reproduce

  • Create some dummy message by the default user:
echo 'test' | php edit.php -u 'MediaWiki default' 'MediaWiki:Test'
  • run php deleteDefaultMessages.php

Expected behaviour: It works. Actual behaviour: UnexpectedValueException from line 162 of /var/www/html/w/includes/user/UserGroupMembership.php: UserGroupMembership::insert() needs a positive user ID. Perhaps addGroup() was called before the user was added to the database.

Event Timeline

Bawolff created this task.Oct 24 2019, 11:08 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 24 2019, 11:08 PM
Bawolff updated the task description. (Show Details)Oct 24 2019, 11:19 PM
Krinkle added a subscriber: Krinkle.

I regularly run deleteEqualMessages.php in production, but haven't in a few weeks recently. Do you expect that script to be affected as well?

I regularly run deleteEqualMessages.php in production, but haven't in a few weeks recently. Do you expect that script to be affected as well?

Looks like:

bawolff@bawolff:/var/www/html/w/maintenance$ php deleteEqualMessages.php  --delete
Checking for pages with default message...
... fetching message info for content language
1 pages in the MediaWiki namespace override messages.
1 pages are equal to the default message (+ 0 talk pages).
Wikimedia\Rdbms\DBQueryError from line 1602 of /var/www/html/w/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: INSERT  INTO `actor` (actor_user,actor_name) VALUES ('3','MediaWiki default')
Function: User::updateActorId
Error: 1062 Duplicate entry 'MediaWiki default' for key 'actor_name' (localhost)

#0 /var/www/html/w/includes/libs/rdbms/database/Database.php(1573): Wikimedia\Rdbms\Database->getQueryExceptionAndLog('Duplicate entry...', 1062, 'INSERT  INTO `a...', 'User::updateAct...')
#1 /var/www/html/w/includes/libs/rdbms/database/Database.php(1152): Wikimedia\Rdbms\Database->reportQueryError('Duplicate entry...', 1062, 'INSERT  INTO `a...', 'User::updateAct...', false)
#2 /var/www/html/w/includes/libs/rdbms/database/Database.php(2139): Wikimedia\Rdbms\Database->query('INSERT  INTO `a...', 'User::updateAct...')
#3 /var/www/html/w/includes/user/User.php(4183): Wikimedia\Rdbms\Database->insert('`actor`', Array, 'User::updateAct...')
#4 /var/www/html/w/includes/user/User.php(4072): User->updateActorId(Object(Wikimedia\Rdbms\DatabaseMysqli))
#5 /var/www/html/w/includes/libs/rdbms/database/Database.php(3965): User::{closure}(Object(Wikimedia\Rdbms\DatabaseMysqli), 'User::createNew')
#6 /var/www/html/w/includes/libs/rdbms/database/DBConnRef.php(68): Wikimedia\Rdbms\Database->doAtomicSection('User::createNew', Object(Closure))
#7 /var/www/html/w/includes/libs/rdbms/database/DBConnRef.php(635): Wikimedia\Rdbms\DBConnRef->__call('doAtomicSection', Array)
#8 /var/www/html/w/includes/user/User.php(4079): Wikimedia\Rdbms\DBConnRef->doAtomicSection('User::createNew', Object(Closure))
#9 /var/www/html/w/includes/user/User.php(775): User::createNew('token', Array)
#10 /var/www/html/w/maintenance/deleteEqualMessages.php(166): User::newSystemUser('MediaWiki defau...', Array)
#11 /var/www/html/w/maintenance/doMaintenance.php(99): DeleteEqualMessages->execute()
#12 /var/www/html/w/maintenance/deleteEqualMessages.php(207): require_once('/var/www/html/w...')
#13 {main}
[1441161cd672c6dbd3af51dc] [no req]   Wikimedia\Rdbms\DBTransactionStateError from line 1419 of /var/www/html/w/includes/libs/rdbms/database/Database.php: Cannot execute query from Wikimedia\Rdbms\Database::ping while transaction status is ERROR
Backtrace:
#0 /var/www/html/w/includes/libs/rdbms/database/Database.php(1145): Wikimedia\Rdbms\Database->assertQueryIsCurrentlyAllowed(string, string)
#1 /var/www/html/w/includes/libs/rdbms/database/Database.php(4295): Wikimedia\Rdbms\Database->query(string, string, integer)
#2 /var/www/html/w/includes/libs/rdbms/database/Database.php(687): Wikimedia\Rdbms\Database->ping(NULL)
#3 /var/www/html/w/includes/libs/rdbms/database/Database.php(677): Wikimedia\Rdbms\Database->pingAndCalculateLastTrxApplyTime()
#4 /var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1605): Wikimedia\Rdbms\Database->pendingWriteQueryDuration(string)
#5 /var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancer.php(2109): Wikimedia\Rdbms\LoadBalancer->Wikimedia\Rdbms\{closure}(Wikimedia\Rdbms\DatabaseMysqli)
#6 /var/www/html/w/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1621): Wikimedia\Rdbms\LoadBalancer->forEachOpenMasterConnection(Closure)
#7 /var/www/html/w/includes/libs/rdbms/lbfactory/LBFactory.php(208): Wikimedia\Rdbms\LoadBalancer->approveMasterChanges(array, string, integer)
#8 /var/www/html/w/includes/libs/rdbms/lbfactory/LBFactorySimple.php(134): Wikimedia\Rdbms\LBFactory->Wikimedia\Rdbms\{closure}(Wikimedia\Rdbms\LoadBalancer, string, array)
#9 /var/www/html/w/includes/libs/rdbms/lbfactory/LBFactory.php(210): Wikimedia\Rdbms\LBFactorySimple->forEachLB(Closure, array)
#10 /var/www/html/w/includes/libs/rdbms/lbfactory/LBFactory.php(269): Wikimedia\Rdbms\LBFactory->forEachLBCallMethod(string, array)
#11 /var/www/html/w/maintenance/doMaintenance.php(124): Wikimedia\Rdbms\LBFactory->commitMasterChanges(string)
#12 /var/www/html/w/maintenance/deleteEqualMessages.php(207): require_once(string)
#13 {main}

However, i don't think this will affect Wikimedia production as MediaWiki default is a real user on enwiki. I think the problem is that the install process treats "MediaWiki default" as an anonymous pseudo-user (i.e. actor_user is null) when it creates the initial Main_Page.

Anomie added a subscriber: Anomie.Oct 28 2019, 2:54 PM

"MediaWiki default" is listed in $wgReservedUsernames, so User::isUsableName() considers it non-usable, so the actor migration allows it to be created with a null actor_user (and without a corresponding row in user). Which is also why the installer isn't needing to create it in the first place.

I have to wonder how that worked before the actor migration, though, as there still wasn't a "MediaWiki default" row in the user table. It seems like it should have been broken when rMW73224f4f8b8a: User group memberships that expire made $user->addGroup() on an anonymous user throw an exception rather than silently ignore it. Probably this is the same as T171315: Running update.php fails on old database which have edits by inexistent user "Mediawiki default", which was presumably not actually fixed.

Change 546636 had a related patch set uploaded (by Anomie; owner: Anomie):
[mediawiki/core@master] Actually create user 'MediaWiki default'

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

"MediaWiki default" is listed in $wgReservedUsernames, so User::isUsableName() considers it non-usable, so the actor migration allows it to be created with a null actor_user (and without a corresponding row in user). Which is also why the installer isn't needing to create it in the first place.

Seems like there might be a general problem with handling of $wgReservedUsernames - There's a complaint about User:RedirectBot (aka msg:double-redirect-fixer) breaking the update process at https://www.mediawiki.org/w/index.php?title=Topic:V9zhfiop5cyc62jv

(remove obsolete comment)

Seems like there might be a general problem with handling of $wgReservedUsernames - There's a complaint about User:RedirectBot (aka msg:double-redirect-fixer) breaking the update process at https://www.mediawiki.org/w/index.php?title=Topic:V9zhfiop5cyc62jv

If there's a general problem, it's with code not ensuring these users exist if they intend to add groups to them... If it's more than "MediaWiki default", perhaps the thing to do is to make User::newSystemUser() be able to clean these up instead of relying on update.php to do it.

Change 546636 merged by jenkins-bot:
[mediawiki/core@master] User: Allow newSystemUser() to create over anonymous actors

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

Anomie closed this task as Resolved.Nov 4 2019, 3:01 PM

deleteDefaultMessages.php should be fixed now.

Shouldn't it be backported to 1.34 (which is a release candidate now)?

Today there was a report from a user upgrading to 1.33.1.

Change 560327 had a related patch set uploaded (by Paladox; owner: Anomie):
[mediawiki/core@REL1_34] User: Allow newSystemUser() to create over anonymous actors

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

Change 560327 merged by jenkins-bot:
[mediawiki/core@REL1_34] User: Allow newSystemUser() to create over anonymous actors

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

@AMooney, I understand that this ticket is resolved. Should it be in the Done or Waiting for Deployment column instead of the Waiting for Review one?