Page MenuHomePhabricator

Argument 1 passed to MediaWiki\User\UserGroupManager::getUserGroups() must implement interface MediaWiki\User\UserIdentity, null given
Closed, ResolvedPublic

Description

Seen in a Selenium test log (gerrit 991084 / jenkins 86658, not related):

13:30:25 mw-error.log:2024-01-18 21:27:14 377c1e1bfff0 wikidb: [7875cc316b784bd9bd611797] /index.php?title=Special:CreateAccount   TypeError: Argument 1 passed to MediaWiki\User\UserGroupManager::getUserGroups() must implement interface MediaWiki\User\UserIdentity, null given, called in /workspace/src/extensions/AbuseFilter/includes/FilterUser.php on line 79
13:30:25 mw-error.log:#0 /workspace/src/extensions/AbuseFilter/includes/FilterUser.php(79): MediaWiki\User\UserGroupManager->getUserGroups(NULL)
13:30:25 mw-error.log:#1 /workspace/src/extensions/AbuseFilter/includes/FilterUser.php(48): MediaWiki\Extension\AbuseFilter\FilterUser->getUser()
13:30:25 mw-error.log:#2 /workspace/src/extensions/AbuseFilter/includes/Hooks/Handlers/CheckUserHandler.php(86): MediaWiki\Extension\AbuseFilter\FilterUser->getUserIdentity()
13:30:25 mw-error.log:#3 /workspace/src/includes/HookContainer/HookContainer.php(161): MediaWiki\Extension\AbuseFilter\Hooks\Handlers\CheckUserHandler->onCheckUserInsertPrivateEventRow(string, boolean, array, MediaWiki\User\User, NULL)
13:30:25 mw-error.log:#4 /workspace/src/extensions/CheckUser/src/Hook/HookRunner.php(80): MediaWiki\HookContainer\HookContainer->run(string, array)
13:30:25 mw-error.log:#5 /workspace/src/extensions/CheckUser/src/Hooks.php(333): MediaWiki\CheckUser\Hook\HookRunner->onCheckUserInsertPrivateEventRow(string, boolean, array, MediaWiki\User\User, NULL)
13:30:25 mw-error.log:#6 /workspace/src/extensions/CheckUser/src/Hooks.php(611): MediaWiki\CheckUser\Hooks::insertIntoCuPrivateEventTable(array, string, MediaWiki\User\User)
13:30:25 mw-error.log:#7 /workspace/src/includes/HookContainer/HookContainer.php(161): MediaWiki\CheckUser\Hooks->onLocalUserCreated(MediaWiki\User\User, boolean)
13:30:25 mw-error.log:#8 /workspace/src/includes/HookContainer/HookRunner.php(2397): MediaWiki\HookContainer\HookContainer->run(string, array)
13:30:25 mw-error.log:#9 /workspace/src/includes/auth/AuthManager.php(1594): MediaWiki\HookContainer\HookRunner->onLocalUserCreated(MediaWiki\User\User, boolean)
13:30:25 mw-error.log:#10 /workspace/src/includes/auth/AuthManager.php(1307): MediaWiki\Auth\AuthManager->continueAccountCreation(array)
13:30:25 mw-error.log:#11 /workspace/src/includes/specialpage/AuthManagerSpecialPage.php(394): MediaWiki\Auth\AuthManager->beginAccountCreation(MediaWiki\User\User, array, string)
13:30:25 mw-error.log:#12 /workspace/src/includes/specialpage/AuthManagerSpecialPage.php(524): MediaWiki\SpecialPage\AuthManagerSpecialPage->performAuthenticationStep(string, array)
13:30:25 mw-error.log:#13 /workspace/src/includes/htmlform/HTMLForm.php(746): MediaWiki\SpecialPage\AuthManagerSpecialPage->handleFormSubmit(array, CodexHTMLForm)
13:30:25 mw-error.log:#14 /workspace/src/includes/specialpage/AuthManagerSpecialPage.php(455): HTMLForm->trySubmit()
13:30:25 mw-error.log:#15 /workspace/src/includes/specialpage/LoginSignupSpecialPage.php(337): MediaWiki\SpecialPage\AuthManagerSpecialPage->trySubmit()
13:30:25 mw-error.log:#16 /workspace/src/includes/specialpage/SpecialPage.php(727): MediaWiki\SpecialPage\LoginSignupSpecialPage->execute(NULL)
13:30:25 mw-error.log:#17 /workspace/src/includes/specialpage/SpecialPageFactory.php(1652): MediaWiki\SpecialPage\SpecialPage->run(NULL)
13:30:25 mw-error.log:#18 /workspace/src/includes/actions/ActionEntryPoint.php(504): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
13:30:25 mw-error.log:#19 /workspace/src/includes/actions/ActionEntryPoint.php(151): MediaWiki\Actions\ActionEntryPoint->performRequest()
13:30:25 mw-error.log:#20 /workspace/src/includes/MediaWikiEntryPoint.php(169): MediaWiki\Actions\ActionEntryPoint->execute()
13:30:25 mw-error.log:#21 /workspace/src/index.php(50): MediaWiki\MediaWikiEntryPoint->run()

The code seems solid, I have no idea how $user could be null.

Event Timeline

This looks to be because FilterUser::getUser makes a call to User::newSystemUser which it expects to return a User and never null. For some reason this assumption was wrong.

Relevant code: https://gerrit.wikimedia.org/g/mediawiki/extensions/AbuseFilter/+/ca2ff0790a81f4b1bf07adcda5c67e65edd64b7a/includes/FilterUser.php#75

Change 991978 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] user: Lock user row when loading system user

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

Change 991978 merged by jenkins-bot:

[mediawiki/core@master] user: Lock user row when loading system user

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

matmarex assigned this task to Tgr.

Hopefully that fixes it. (I haven't been able to reproduce the problem and test the fix locally.)

I didn't locally reproduce it either, but the INSERT IGNORE failing due to a unique key conflict seemed like the only possible code path that could lead to null. Let's see if the error persists.