Page MenuHomePhabricator

UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value (via GlobalUsage)
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
labels.normalized_message
[{reqId}] {exception_url}   UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value
error.stack_trace
from /srv/mediawiki/php-1.42.0-wmf.26/includes/libs/rdbms/querybuilder/InsertQueryBuilder.php(324)
#0 /srv/mediawiki/php-1.42.0-wmf.26/extensions/GlobalUsage/includes/GlobalUsage.php(190): Wikimedia\Rdbms\InsertQueryBuilder->execute()
#1 [internal function]: MediaWiki\Extension\GlobalUsage\GlobalUsage->MediaWiki\Extension\GlobalUsage\{closure}()
#2 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/MWCallableUpdate.php(42): call_user_func(Closure)
#3 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdates.php(486): MediaWiki\Deferred\MWCallableUpdate->doUpdate()
#4 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdates.php(198): MediaWiki\Deferred\DeferredUpdates::attemptUpdate(MediaWiki\Deferred\MWCallableUpdate)
#5 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdates.php(285): MediaWiki\Deferred\DeferredUpdates::run(MediaWiki\Deferred\MWCallableUpdate)
#6 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdatesScope.php(269): MediaWiki\Deferred\DeferredUpdates::MediaWiki\Deferred\{closure}(MediaWiki\Deferred\MWCallableUpdate, integer)
#7 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdatesScope.php(198): MediaWiki\Deferred\DeferredUpdatesScope->processStageQueue(integer, integer, Closure)
#8 /srv/mediawiki/php-1.42.0-wmf.26/includes/deferred/DeferredUpdates.php(304): MediaWiki\Deferred\DeferredUpdatesScope->processUpdates(integer, Closure)
#9 /srv/mediawiki/php-1.42.0-wmf.26/includes/MediaWikiEntryPoint.php(672): MediaWiki\Deferred\DeferredUpdates::doUpdates()
#10 /srv/mediawiki/php-1.42.0-wmf.26/includes/MediaWikiEntryPoint.php(495): MediaWiki\MediaWikiEntryPoint->restInPeace()
#11 /srv/mediawiki/php-1.42.0-wmf.26/includes/MediaWikiEntryPoint.php(453): MediaWiki\MediaWikiEntryPoint->doPostOutputShutdown()
#12 /srv/mediawiki/php-1.42.0-wmf.26/includes/MediaWikiEntryPoint.php(208): MediaWiki\MediaWikiEntryPoint->postOutputShutdown()
#13 /srv/mediawiki/php-1.42.0-wmf.26/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#14 /srv/mediawiki/w/index.php(3): require(string)
#15 {main}
Notes
  • Started on 2024-04-10 with wmf.26 to group1 wikis
  • Happening mostly on Wikipedias (a few Wikis as well all group1)
  • Rate of about 4 an hour

Event Timeline

July 2023:

.. which included an exception for empty $rows unlike the old insert() method.

.. and was changed it to a warning T347610: UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value (via WatchedItemStore::updateExpiries)

Nov 2023:

Revert "InsertQueryBuilder: When passed no rows, warn rather than die for now"
Reason for revert: Once we're happy these have been resolved in prod.
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/963365

… which restored the exception.

2 April 2024:

Migrate to IDatabase::newInsertQueryBuilder/newDeleteQueryBuilder
https://gerrit.wikimedia.org/r/c/mediawiki/extensions/GlobalUsage/+/1016403

… which updated GlobalUsage to use the stricter InsertQueryBuilder

/cc @Umherirrender @Jdforrester-WMF

We have also:

14 April 2024:

Protect GlobalUsage::copyLocalImagelinks for empty row set

InsertQueryBuilder does not ignore inserts with empty rows
as IDatabase::insert does.

Follow-Up: Ib79d9920355d1a3a582d252698c33e34f77d9c78

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/GlobalUsage/+/1019410

Which presumalby fixed this fatal error, maybe warrants a backport, if it weren't Thursday already and it's already in the next branch (wmf.1) which is going out to the remaining groups later today.

Actually, it seems the above patch did not fix the issue.

In Logstash we have on 1.42.0-wmf.26:

UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value

#0 /srv/mediawiki/php-1.42.0-wmf.26/extensions/GlobalUsage/includes/GlobalUsage.php(190): Wikimedia\Rdbms\InsertQueryBuilder->execute()
…

And then on the next branch, the exact same failure is still seen, from the same file and logical line (line 190 is now 194, given the 4 added lines from the above patch, showing that the patch is definitely included in the branch):

UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value

#0 /srv/mediawiki/php-1.43.0-wmf.1/extensions/GlobalUsage/includes/GlobalUsage.php(194): Wikimedia\Rdbms\InsertQueryBuilder->execute()
…

This is quite strange since the !$res check seems pretty definitive, but I guess it isn't? One possible explanation for how $res can be truthy and yet not have any loop iterations is that it is a IResultWrapper object, which is iterable and countable, but unlike primitive arrays, cannot cast to boolean false.

Change #1021525 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/extensions/GlobalUsage@master] Use IResultWrapper::numRows to check for empty IResultWrapper

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

When \Wikimedia\Rdbms\IReadableDatabase::select() is typehinted to return \Wikimedia\Rdbms\IResultWrapper phan reports:
PhanRedundantCondition Redundant attempt to cast $res of type \Wikimedia\Rdbms\IResultWrapper to truthy
But without typehint phan is not strict here.

Change #1021525 merged by jenkins-bot:

[mediawiki/extensions/GlobalUsage@master] Use IResultWrapper::numRows to check for empty IResultWrapper

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

Change #1020941 had a related patch set uploaded (by Jforrester; author: Umherirrender):

[mediawiki/extensions/GlobalUsage@wmf/1.43.0-wmf.1] Use IResultWrapper::numRows to check for empty IResultWrapper

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

When \Wikimedia\Rdbms\IReadableDatabase::select() is typehinted to return \Wikimedia\Rdbms\IResultWrapper phan reports:
PhanRedundantCondition Redundant attempt to cast $res of type \Wikimedia\Rdbms\IResultWrapper to truthy
But without typehint phan is not strict here.

Cannot add a return type hint due to QUERY_SILENCE_ERRORS
See https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1021587 for the query builder

Change #1020941 abandoned by Umherirrender:

[mediawiki/extensions/GlobalUsage@wmf/1.43.0-wmf.1] Use IResultWrapper::numRows to check for empty IResultWrapper

Reason:

Not longer needed, 1.43.0-wmf.2 is everywhere

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

Umherirrender renamed this task from UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value to UnexpectedValueException: Wikimedia\Rdbms\InsertQueryBuilder::execute can't have empty $rows value (via GlobalUsage).May 7 2024, 6:29 PM