Page MenuHomePhabricator

SitemapFileHandler: PHP Deprecated: Implicit conversion from float 33333.333333333336 to int loses precision
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
  • service.version: 1.46.0-wmf.4
  • timestamp: 2025-12-03T07:48:20.953Z
  • labels.phpversion: 8.3.26
  • trace.id: bb96ac0c-4a39-4124-a1f5-36fd0c6b1c76
  • Find trace.id in Logstash
labels.normalized_message
[{reqId}] {exception_url}   PHP Deprecated: Implicit conversion from float 33333.333333333336 to int loses precision
FrameLocationCall
from/srv/mediawiki/php-1.46.0-wmf.4/includes/Page/SitemapGenerator.php(147)
#0/srv/mediawiki/php-1.46.0-wmf.4/includes/Page/SitemapGenerator.php(147)MediaWiki\Exception\MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Handler/SitemapFileHandler.php(98)MediaWiki\Page\SitemapGenerator->idRange(int, float)
#2/srv/mediawiki/php-1.46.0-wmf.4/includes/libs/ObjectCache/WANObjectCache.php(1825)MediaWiki\Rest\Handler\SitemapFileHandler->MediaWiki\Rest\Handler\{closure}(bool, int, array, null, array)
#3/srv/mediawiki/php-1.46.0-wmf.4/includes/libs/ObjectCache/WANObjectCache.php(1635)Wikimedia\ObjectCache\WANObjectCache->fetchOrRegenerate(string, int, Closure, array, array)
#4/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Handler/SitemapFileHandler.php(86)Wikimedia\ObjectCache\WANObjectCache->getWithSetCallback(string, int, Closure, array)
#5/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Handler/SitemapFileHandler.php(70)MediaWiki\Rest\Handler\SitemapFileHandler->getData()
#6/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Handler/SitemapHandlerBase.php(58)MediaWiki\Rest\Handler\SitemapFileHandler->getXml()
#7/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Module/Module.php(452)MediaWiki\Rest\Handler\SitemapHandlerBase->execute()
#8/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Module/Module.php(301)MediaWiki\Rest\Module\Module->executeHandler(MediaWiki\Rest\Handler\SitemapFileHandler)
#9/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Router.php(485)MediaWiki\Rest\Module\Module->execute(string, MediaWiki\Rest\RequestFromGlobals)
#10/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/Router.php(444)MediaWiki\Rest\Router->doExecute(string, MediaWiki\Rest\RequestFromGlobals)
#11/srv/mediawiki/php-1.46.0-wmf.4/includes/Rest/EntryPoint.php(207)MediaWiki\Rest\Router->execute(MediaWiki\Rest\RequestFromGlobals)
#12/srv/mediawiki/php-1.46.0-wmf.4/includes/MediaWikiEntryPoint.php(184)MediaWiki\Rest\EntryPoint->execute()
#13/srv/mediawiki/php-1.46.0-wmf.4/rest.php(25)MediaWiki\MediaWikiEntryPoint->run()
#14/srv/mediawiki/w/rest.php(3)require(string)
#15{main}
Impact
Notes

The start and end ids come from a getOffset method:

protected function getOffset( $indexId, $fileId ) {
    return $this->sitemapSize * ( $indexId * $this->indexSize + $fileId );
}

The sitemapSize property is set when creating the SitemapFileHandler and is a float:

includes/Rest/Handler/SitemapHandlerBase.php
$this->sitemapSize = ( $apiConf['pagesPerSitemap'] ?? 10_000 ) / ( count( $variants ) + 1 );

But an integer is required:

includes/Page/SitemapGenerator.php
public function idRange( ?int $startId, ?int $endId ) {
    $this->startId = $startId;
    $this->endId = $endId;
    return $this;
}

Event Timeline

The Page::SitemapGenerator() requires int and it passed a float by SitemapGenerator which get a float on construction:

$this->sitemapSize = ( $apiConf['pagesPerSitemap'] ?? 10_000 ) / ( count( $variants ) + 1 );

I guess that can simply by casted to integer using (int).

Reedy triaged this task as Medium priority.Dec 3 2025, 3:20 PM
Reedy subscribed.

Noting this is farily spammy, but for many different values in a 15 minute period - 40+ different normalized message lines with ~2 for each

Change #1214609 had a related patch set uploaded (by BPirkle; author: BPirkle):

[mediawiki/core@master] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

For future reference, this wasn't caught in CI or Beta because most wikis don't have language variants or have a number that you can divide 10000 by without a remainder (e.g. 1, 2, 4, 5, etc). This includes the piglatin test variant in CI, which adds to English for 2 variants total.

Ref codesearch query.

uz.wikipedia.org with its UzConverter has 3 variants, hence that produces a float.

Change #1214609 merged by jenkins-bot:

[mediawiki/core@master] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

Change #1214724 had a related patch set uploaded (by Reedy; author: BPirkle):

[mediawiki/core@REL1_45] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

Change #1214724 merged by jenkins-bot:

[mediawiki/core@REL1_45] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

Change #1215078 had a related patch set uploaded (by Hashar; author: BPirkle):

[mediawiki/core@wmf/1.46.0-wmf.5] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

Change #1215078 merged by jenkins-bot:

[mediawiki/core@wmf/1.46.0-wmf.5] REST: add explicit cast to sitemapSize calcuation to avoid warning

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

Mentioned in SAL (#wikimedia-operations) [2025-12-04T09:20:30Z] <hashar@deploy2002> Started scap sync-world: Backport for [[gerrit:1215078|REST: add explicit cast to sitemapSize calcuation to avoid warning (T411580)]], [[gerrit:1214647|Followup I81a2c4: Verify stats label values are not empty (T411585)]]

Mentioned in SAL (#wikimedia-operations) [2025-12-04T09:23:00Z] <hashar@deploy2002> jforrester, hashar: Backport for [[gerrit:1215078|REST: add explicit cast to sitemapSize calcuation to avoid warning (T411580)]], [[gerrit:1214647|Followup I81a2c4: Verify stats label values are not empty (T411585)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2025-12-04T09:30:29Z] <hashar@deploy2002> Finished scap sync-world: Backport for [[gerrit:1215078|REST: add explicit cast to sitemapSize calcuation to avoid warning (T411580)]], [[gerrit:1214647|Followup I81a2c4: Verify stats label values are not empty (T411585)]] (duration: 09m 59s)

hashar assigned this task to BPirkle.

Thank you for the fix, I have deployed the backport before running the train.