Page MenuHomePhabricator

SiteSQLStoreTest::testGetSites fails with 'null value in column "site_id" violates not-null constraint'
Closed, DeclinedPublic

Description

Change-Id I3f47675646d772 converts from explicit transactions to using "startAtomic", which according to the documentation is more strict than directly using transactions.

This breaks phpunit tests for PostgreSQL. Not just a specific test fails, rather it breaks the testing framework itself.

I don't know where this bug might be, I suspect there might more than one of them involved.. It seems like, if nothing else, the unit test should at least catch the error and report it, rather than aborting the test sequence. But I don't why it isn't doing that.

PHP Notice:  DatabasePostgres::reportQueryError: Explicit rollback of implicit transaction. Something may be out of sync! [Called from DatabaseBase::rollback in /usr/local/apache2/htdocs/wiki_git/includes/db/Database.php at line 3620] in /usr/local/apache2/htdocs/wiki_git/includes/debug/MWDebug.php on line 302
PHP Stack trace:
PHP   1. {main}() /usr/local/apache2/htdocs/wiki_git/tests/phpunit/phpunit.php:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/apache2/htdocs/wiki_git/tests/phpunit/phpunit.php:233
PHP   3. PHPUnit_TextUI_Command->run() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/TextUI/Command.php:138
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/TextUI/Command.php:186
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP   7. PHPUnit_Framework_TestSuite->run() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP   8. MediaWikiTestCase->run() /usr/local/apache2/htdocs/wiki_git/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP   9. MediaWikiTestCase->addCoreDBData() /usr/local/apache2/htdocs/wiki_git/tests/phpunit/MediaWikiTestCase.php:133
PHP  10. User->idForName() /usr/local/apache2/htdocs/wiki_git/tests/phpunit/MediaWikiTestCase.php:470
PHP  11. DatabaseBase->selectField() /usr/local/apache2/htdocs/wiki_git/includes/User.php:3526
PHP  12. DatabaseBase->select() /usr/local/apache2/htdocs/wiki_git/includes/db/Database.php:1360
PHP  13. DatabaseBase->query() /usr/local/apache2/htdocs/wiki_git/includes/db/Database.php:1650
PHP  14. DatabasePostgres->reportQueryError() /usr/local/apache2/htdocs/wiki_git/includes/db/Database.php:1182
PHP  15. DatabaseBase->rollback() /usr/local/apache2/htdocs/wiki_git/includes/db/DatabasePostgres.php:536
PHP  16. wfWarn() /usr/local/apache2/htdocs/wiki_git/includes/db/Database.php:3620
PHP  17. MWDebug::warning() /usr/local/apache2/htdocs/wiki_git/includes/GlobalFunctions.php:1159
PHP  18. MWDebug::sendMessage() /usr/local/apache2/htdocs/wiki_git/includes/debug/MWDebug.php:157
PHP  19. trigger_error() /usr/local/apache2/htdocs/wiki_git/includes/debug/MWDebug.php:302
A database query error has occurred.
Query: SELECT  user_id  FROM "unittest_mwuser"   WHERE user_name = 'UTSysop'  LIMIT 1
Function: User::idForName
Error: 25P02 ERROR:  current transaction is aborted, commands ignored until end of transaction block

Version: 1.25-git
Severity: normal

Details

Reference
bz73139

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.

Event Timeline

bzimport raised the priority of this task from to Normal.
bzimport set Reference to bz73139.
bzimport added a subscriber: Unknown Object (MLST).
Jjanes created this task.Nov 7 2014, 5:22 PM
scfc added a comment.Nov 11 2014, 1:46 AM

Indeed master + Jeff's Gerrit change #170395 fails (cf. https://travis-ci.org/scfc/mediawiki-core/jobs/40611418).

Marcin, IIRC you fixed a lot of transaction-related PostgreSQL bugs many moons ago; do you have a grasp of the current design?

saper added a comment.Nov 11 2014, 9:41 PM

do we know which test is causing this?

saper added a comment.EditedNov 11 2014, 9:58 PM

With current master (and a change to nuke INSERT IGNORE in the updater) I am running

php tests/phpunit/phpunit.php --configuration tests/phpunit/suite.xml --exclude-group Broken,Stub,Dump,ParserFuzz

and I get 5 errors:

ImportTest::testHandlePageContainsRedirect with data set #0 ('<mediawiki ...

MWException: Cannot create InputStreamSource.

ImportTest::testHandlePageContainsRedirect with data set #1

MWException: Cannot create InputStreamSource.

TestORMRowTest::testSaveAndRemove

which is T75139

SiteSQLStoreTest::testGetSites

DBQueryError: A database error has occurred. Did you forget to run maintenance/update.php after upgrading?  See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: INSERT INTO "unittest_sites" (site_id,site_global_key,site_type,site_group,site_source,site_language,site_protocol,site_domain,site_data,site_forward,site_config) VALUES (NULL,'foobar','unknown','none','local','','','.','a:0:{}',0,'a:0:{}')
Function: SiteSQLStore::saveSites
Error: 23502 ERROR:  null value in column "site_id" violates not-null constraint

which is probably what we are getting here?

SiteSQLStoreTest::testSaveSites

DBQueryError: A database error has occurred. Did you forget to run maintenance/update.php after upgrading?  See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: INSERT INTO "unittest_sites" (site_id,site_global_key,site_type,site_group,site_source,site_language,site_protocol,site_domain,site_data,site_forward,site_config) VALUES (NULL,'ertrywuutr','unknown','none','local','en','','.','a:0:{}',0,'a:0:{}')
Function: SiteSQLStore::saveSites
Error: 23502 ERROR:  null value in column "site_id" violates not-null constraint

and then 18 test failures:

  1. PrefixSearchTest::testSearch
  2. SpecialPageTest::testInvalidGetTitleFor Failed asserting that exception of type "PHPUnit_Framework_Error_Notice" is thrown.
  3. SpecialPageTest::testGetTitleForWithWarning with data set #0 (Special:UserLogin, 'UserLogin') Failed asserting that exception of type "PHPUnit_Framework_Error_Notice" is thrown.
  4. WikiPageTest::testDoDeleteArticle (known issue)
  5. WikiPageTest::testDoDeleteUpdates (known issue)
  6. SiteSQLStoreTest::testReset (probably related to the error above)

and some TextPassDumperTest and FetchTextTest failures

15 tests were skipped

The test that fails is:

php tests/phpunit/phpunit.php tests/phpunit/includes/site/SiteSQLStoreTest.php

Only it presents differently for me, taking down the test framework rather than just failing in the ordinary way.

I wonder if the behavior depends on the version of the php library used to talk to pgsql. I don't know how to figure that out. I'm using CentOS 6.6 and PHP 5.3.3 (cli) (built: Oct 30 2014 20:12:53).

First I have you run into the issue (which got fixed in the meantime) that the transaction error overshadowed any real database error during testing - this was I think bug 58095.

on my installation it seems that the problem is with SiteSQLStoreTest -
after applying by hand my fix in gerrit change 100183.

Actually those problems were already mentioned in bug 43475

Can we check if teaching "ORM" to use sequences fixes the problem?

Please try gerrit change 100183 - it should fix this (and some other "ORM" tests as well).

Gerrit change #100183 fixes the distal problem, but not the proximal problem that the test suite should not fall over when one test in it fails.

Bug 58095 is marked closed, should that be reopened?

saper added a comment.Nov 12 2014, 1:12 AM

Can we double check if fix for bug 58095 (gerrit change 136287 - it's yours) is included in our build on travis?

I wonder why it works for me...

saper updated the task description. (Show Details)Nov 27 2014, 11:52 AM
saper set Security to None.
Jdforrester-WMF added a subscriber: Jdforrester-WMF.

Migrating from the old tracking task to a tag for PostgreSQL-related tasks.

Krinkle closed this task as Declined.Mar 14 2017, 10:20 PM
Krinkle added a subscriber: Krinkle.

Not seeing this anymore as of T75174#3052122.