Page MenuHomePhabricator

Wikimedia\Rdbms\DBQueryError: Error 1054: Unknown column 'cec_user_name__str' in 'WHERE'Function: MediaWiki\Pager\IndexPager::buildQueryInfo (MediaWiki\Extension\CampaignEvents\Pager\EventContributionsPager)Query: SELECT cec
Open, Needs TriagePublicPRODUCTION ERROR

Description

Error
  • service.version: 1.46.0-wmf.13
  • timestamp: 2026-02-05T10:30:03.624Z
  • labels.phpversion: 8.3.30
  • trace.id: 7e3cfa40-2213-48a0-a4cd-14c95392b876
  • Find trace.id in Logstash
labels.normalized_message
[{reqId}] {exception_url}   Wikimedia\Rdbms\DBQueryError: Error 1054: Unknown column 'cec_user_name__str' in 'WHERE'
Function: MediaWiki\Pager\IndexPager::buildQueryInfo (MediaWiki\Extension\CampaignEvents\Pager\EventContributionsPager)
Query: SELECT  cec
Notes

The cec_user_name_str is not a schema, that is an alias for COALESCE(cec_user_name, ""). That was introduced in October by https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CampaignEvents/+/1200073 for T404995

Stacktrace
FrameLocationCall
from/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/Database.php(1226)
#0/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/Database.php(1210)Wikimedia\Rdbms\Database->getQueryException(string, int, string, string)
#1/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/Database.php(1184)Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, int, string, string)
#2/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/Database.php(641)Wikimedia\Rdbms\Database->reportQueryError(string, int, string, string, bool)
#3/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/Database.php(1364)Wikimedia\Rdbms\Database->query(Wikimedia\Rdbms\Query, string)
#4/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/DBConnRef.php(129)Wikimedia\Rdbms\Database->select(array, array, array, string, array, array)
#5/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/Database/DBConnRef.php(386)Wikimedia\Rdbms\DBConnRef->__call(string, array)
#6/srv/mediawiki/php-1.46.0-wmf.13/includes/libs/Rdbms/QueryBuilder/SelectQueryBuilder.php(761)Wikimedia\Rdbms\DBConnRef->select(array, array, array, string, array, array)
#7/srv/mediawiki/php-1.46.0-wmf.13/includes/Pager/IndexPager.php(468)Wikimedia\Rdbms\SelectQueryBuilder->fetchResultSet()
#8/srv/mediawiki/php-1.46.0-wmf.13/includes/Pager/IndexPager.php(259)MediaWiki\Pager\IndexPager->reallyDoQuery(string, int, bool)
#9/srv/mediawiki/php-1.46.0-wmf.13/includes/Pager/IndexPager.php(891)MediaWiki\Pager\IndexPager->doQuery()
#10/srv/mediawiki/php-1.46.0-wmf.13/includes/Pager/CodexTablePager.php(280)MediaWiki\Pager\IndexPager->isNavigationBarShown()
#11/srv/mediawiki/php-1.46.0-wmf.13/includes/Pager/CodexTablePager.php(59)MediaWiki\Pager\CodexTablePager->getNavigationBar()
#12/srv/mediawiki/php-1.46.0-wmf.13/extensions/CampaignEvents/src/FrontendModules/EventContributionsModule.php(175)MediaWiki\Pager\CodexTablePager->getFullOutput()
#13/srv/mediawiki/php-1.46.0-wmf.13/extensions/CampaignEvents/src/Special/SpecialEventDetails.php(222)MediaWiki\Extension\CampaignEvents\FrontendModules\EventContributionsModule->createContent()
#14/srv/mediawiki/php-1.46.0-wmf.13/includes/SpecialPage/SpecialPage.php(711)MediaWiki\Extension\CampaignEvents\Special\SpecialEventDetails->execute(string)
#15/srv/mediawiki/php-1.46.0-wmf.13/includes/SpecialPage/SpecialPageFactory.php(1747)MediaWiki\SpecialPage\SpecialPage->run(string)
#16/srv/mediawiki/php-1.46.0-wmf.13/includes/Actions/ActionEntryPoint.php(504)MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, MediaWiki\Context\RequestContext)
#17/srv/mediawiki/php-1.46.0-wmf.13/includes/Actions/ActionEntryPoint.php(144)MediaWiki\Actions\ActionEntryPoint->performRequest()
#18/srv/mediawiki/php-1.46.0-wmf.13/includes/MediaWikiEntryPoint.php(180)MediaWiki\Actions\ActionEntryPoint->execute()
#19/srv/mediawiki/php-1.46.0-wmf.13/index.php(44)MediaWiki\MediaWikiEntryPoint->run()
#20/srv/mediawiki/w/index.php(3)require(string)
#21{main}

Acceptance criteria for testing

  • Given an event has at least one suppressed user who has contributions (and who should therefore appear as "deleted user" in the contributions table)
  • When I am looking at the contributions table in Special:EventDetails for that event
  • If I sort the table by user
    • Then the sorting should work
  • If I change page (next, previous, etc.) while sorted by user
    • Then pagination should work and all users should be displayed at some point
  • If I then change the sorting direction (while still sorted by user)
    • Then navigation should still work (changing page and verifying all users are still shown)
  • In particular, the bug described in T404995#11321541 should not happen

(Note: this can be tested with few edits by changing the row limit to something small in the URL, e.g. appending &limit=5

Details

Request URL
https://ee.wikipedia.org/w/index.php?asc=*&desc=*&offset=*&sort=*&tab=*&title=*
Related Changes in Gerrit:

Event Timeline

Restricted Application added a project: Connection-Team. · View Herald Transcript
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Huh, so... I had tested this in SQLite, where it works as expected... But you can't use aliases in WHERE in MySQL (docs). Indeed, I can reproduce the error easily at https://meta.wikimedia.org/w/index.php?title=Special:EventDetails/2592&sort=username&tab=ContributionsPanel&offset=256One%7C20251215233943%7C6307. So we'll need to look into an alternative

And FTR, the query is something like this:

SELECT  cec_id,cec_event_id, cec_page_prefixedtext, cec_wiki, cec_user_id, cec_user_name, COALESCE(cec_user_name, "") AS `cec_user_name__str`, cec_timestamp, cec_bytes_delta, cec_links_delta, cec_edit_flags, cec_revision_id, cec_page_id, cec_deleted, cep_private
FROM `ce_event_contributions` `cec`
JOIN `ce_participants` `cep` ON ((cec.cec_event_id = cep.cep_event_id) AND (cec.cec_user_id = cep.cep_user_id) AND cep.cep_unregistered_at IS NULL)
WHERE cec.cec_event_id = 1234 AND cec.cec_deleted = 0 AND cep.cep_private = 0 AND (cec_user_name__str > 'Foo' OR (cec_user_name__str = 'Foo' AND (cec_timestamp > '20260101120000' OR (cec_timestamp = '20260101120000' AND (cec_id > '4321')))))
ORDER BY cec_user_name__str,cec_timestamp,cec_id
LIMIT 51

I'm taking a look at this, I'll just need some time to setup a test case in mariadb locally...

Change #1237267 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/CampaignEvents@master] EventContributionsPager: avoid using alias in WHERE clause

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

I'm taking a look at this, I'll just need some time to setup a test case in mariadb locally...

You can also have a PHPUnit test to cover it, CI runs it under MariaDB ;-)

I do not know about the impact, but if it is serious enough the fix can be backported and deployed today ( https://wikitech.wikimedia.org/wiki/Deployments/Emergencies ). Note: SRE needs to be made aware a deployment will occur.

I'm taking a look at this, I'll just need some time to setup a test case in mariadb locally...

You can also have a PHPUnit test to cover it, CI runs it under MariaDB ;-)

Good point. It might be a bit annoying because it's a pager class (so not very easy to test) so no guarantees, but I'll take a stab.

I do not know about the impact, but if it is serious enough the fix can be backported and deployed today ( https://wikitech.wikimedia.org/wiki/Deployments/Emergencies ). Note: SRE needs to be made aware a deployment will occur.

This only occurs if sorting by username and changing page. It doesn't seem to happen very often, and the bug has been there for a while already, so it surely can wait next train ;)