Page MenuHomePhabricator

CheckUser causes a foreign key constraint failure on PostgreSQL when creating a new user
Open, Needs TriagePublic

Description

After installing the CheckUser extension on MediaWiki 1.33.1 and a PostgreSQL database, it is not possible to create a new user due to the following error. Obviously, there can't be a page with page_id = 0, so why is cuc_page_id being set to 0? It should be NULL if it is unknown/non-existent...

This is a very similar or even the same case as T149973.

[a14de166292ecc11ddb7703a] /index.php/Special:CreateAccount Wikimedia\Rdbms\DBQueryError from line 1587 of /srv/http/LocalArchWiki/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 "cu_changes" (cuc_page_id,cuc_namespace,cuc_title,cuc_minor,cuc_user,cuc_user_text,cuc_actiontext,cuc_comment,cuc_this_oldid,cuc_last_oldid,cuc_type,cuc_timestamp,cuc_ip,cuc_ip_hex,cuc_xff,cuc_xff_hex,cuc_agent) VALUES ('0','2','','0','7','Test','was created','','0','0','3','2020-01-03 10:42:48+00','127.0.0.1','7F000001',0,NULL,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.14.0 Chrome/77.0.3865.129 Safari/537.36')
Function: CheckUserHooks::logUserAccountCreation
Error: 23503 ERROR: insert or update on table "cu_changes" violates foreign key constraint "cu_changes_cuc_page_id_fkey"
DETAIL: Key (cuc_page_id)=(0) is not present in table "page".

Backtrace:

#0 /srv/http/LocalArchWiki/includes/libs/rdbms/database/Database.php(1556): Wikimedia\Rdbms\Database->getQueryExceptionAndLog()
#1 /srv/http/LocalArchWiki/includes/libs/rdbms/database/Database.php(1274): Wikimedia\Rdbms\Database->reportQueryError()
#2 /srv/http/LocalArchWiki/includes/libs/rdbms/database/DatabasePostgres.php(621): Wikimedia\Rdbms\Database->query()
#3 /srv/http/LocalArchWiki/extensions/CheckUser/includes/CheckUserHooks.php(248): Wikimedia\Rdbms\DatabasePostgres->insert()
#4 /srv/http/LocalArchWiki/extensions/CheckUser/includes/CheckUserHooks.php(209): CheckUserHooks::logUserAccountCreation()
#5 /srv/http/LocalArchWiki/includes/Hooks.php(174): CheckUserHooks::onLocalUserCreated()
#6 /srv/http/LocalArchWiki/includes/Hooks.php(234): Hooks::callHook()
#7 /srv/http/LocalArchWiki/includes/auth/AuthManager.php(1426): Hooks::runWithoutAbort()
#8 /srv/http/LocalArchWiki/includes/auth/AuthManager.php(1143): MediaWiki\Auth\AuthManager->continueAccountCreation()
#9 /srv/http/LocalArchWiki/includes/specialpage/AuthManagerSpecialPage.php(357): MediaWiki\Auth\AuthManager->beginAccountCreation()
#10 /srv/http/LocalArchWiki/includes/specialpage/AuthManagerSpecialPage.php(482): AuthManagerSpecialPage->performAuthenticationStep()
#11 /srv/http/LocalArchWiki/includes/htmlform/HTMLForm.php(660): AuthManagerSpecialPage->handleFormSubmit()
#12 /srv/http/LocalArchWiki/includes/specialpage/AuthManagerSpecialPage.php(416): HTMLForm->trySubmit()
#13 /srv/http/LocalArchWiki/includes/specialpage/LoginSignupSpecialPage.php(313): AuthManagerSpecialPage->trySubmit()
#14 /srv/http/LocalArchWiki/includes/specialpage/SpecialPage.php(569): LoginSignupSpecialPage->execute()
#15 /srv/http/LocalArchWiki/includes/specialpage/SpecialPageFactory.php(558): SpecialPage->run()
#16 /srv/http/LocalArchWiki/includes/MediaWiki.php(288): MediaWiki\Special\SpecialPageFactory->executePath()
#17 /srv/http/LocalArchWiki/includes/MediaWiki.php(865): MediaWiki->performRequest()
#18 /srv/http/LocalArchWiki/includes/MediaWiki.php(515): MediaWiki->main()
#19 /srv/http/LocalArchWiki/index.php(42): MediaWiki->run()
#20 {main}

Event Timeline

saper renamed this task from Database error on PostgreSQL when creating a new user to CheckUser causes a foreign key constraint failure on PostgreSQL when creating a new user.Jan 3 2020, 12:45 PM

Change 561848 had a related patch set uploaded (by saper; owner: saper):
[mediawiki/extensions/CheckUser@master] T241827: Set cuc_page_id to zero only on MySQL

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

Yes, I was able to create a user with that patch.

Great, we should just test it with MySQL and here we go...