Page MenuHomePhabricator

Resolve type errors caused by data type changes in test Wikidata
Closed, ResolvedPublicPRODUCTION ERROR

Description

Currently, there are a couple of pages (Item, Lexeme) on test Wikidata which errors when we try to index it for a search. The frequency of this error over the last week was 6 times for 7 days which leads to some amount of logspam.

Acceptance Criteria:

  • The error no longer occurs (seems to be caused by the data type changes mentioned in the comments below. See method: Wikibase\Search\Elastic\Fields\StatementsField::getSnakAsPropertyIdAndValue)
  • After deployment, we’ve also looked at the suspected duplicate T380376 and either closed it as well (if it was fixed by the same changes) or moved it out of Stalled status (if it’s something different after all).

Notes:

The error can be reproduce locally by:

  1. creating a property with data type “Point in time”
  2. creating a statement with that property and a time value
  3. commenting out the assertDataTypesCompatible() check in PropertyDataTypeChanger::changeDataType()
  4. using the repo/maintenance/changePropertyDataType.php maintenance script to change the data type of the property from “Point in time” to “String” (--new-data-type=string)
  5. making sure WikibaseCirrusSearch is loaded, $wgSearchType is 'CirrusSearch', $wgWBCSUseCirrus is true, and $wgWBRepoSettings['searchIndexTypes'] includes 'string'
  6. getting WikibaseCirrusSearch to re-index the entity with the now-broken statement, using an API call similar to the one in T372993#10104381
    • you might have to clear your MediaWiki cache first (e.g. restart memcached or truncate the objectcache database table)

Original Title / Error Message:

TypeError: Argument 1 passed to Wikimedia\Services\ServiceContainer::{closure}() must be an instance of DataValues\StringValue, instance of DataValues\TimeValue given, called in extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php:177

Original Report:

Error
labels.normalized_message
[{reqId}] {exception_url}   TypeError: Argument 1 passed to Wikimedia\Services\ServiceContainer::{closure}() must be an instance of DataValues\StringValue, instance of DataValues\TimeValue given, called in /srv/mediawiki/php-1.43.0-wmf.19/extensions/Wikib
error.stack_trace
from /srv/mediawiki/php-1.43.0-wmf.19/extensions/Wikibase/repo/WikibaseRepo.datatypes.php(297)
#0 /srv/mediawiki/php-1.43.0-wmf.19/extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php(177): Wikimedia\Services\ServiceContainer->{closure}(DataValues\TimeValue)
#1 /srv/mediawiki/php-1.43.0-wmf.19/extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php(196): Wikibase\Search\Elastic\Fields\StatementsField->getSnakAsPropertyIdAndValue(Wikibase\DataModel\Snak\PropertyValueSnak, string)
#2 /srv/mediawiki/php-1.43.0-wmf.19/extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php(132): Wikibase\Search\Elastic\Fields\StatementsField->getSnakAsString(Wikibase\DataModel\Snak\PropertyValueSnak)
#3 /srv/mediawiki/php-1.43.0-wmf.19/extensions/Wikibase/repo/includes/Content/EntityHandler.php(715): Wikibase\Search\Elastic\Fields\StatementsField->getFieldData(Wikibase\DataModel\Entity\Item)
#4 /srv/mediawiki/php-1.43.0-wmf.19/extensions/Wikibase/repo/includes/Content/EntityHandler.php(696): Wikibase\Repo\Content\EntityHandler->getContentDataForSearchIndex(Wikibase\Repo\Content\ItemContent)
#5 /srv/mediawiki/php-1.43.0-wmf.19/extensions/CirrusSearch/includes/BuildDocument/ParserOutputPageProperties.php(106): Wikibase\Repo\Content\EntityHandler->getDataForSearchIndex(WikiPage, MediaWiki\Parser\ParserOutput, CirrusSearch\CirrusSearch, MediaWiki\Revision\RevisionStoreRecord)
#6 /srv/mediawiki/php-1.43.0-wmf.19/includes/libs/objectcache/wancache/WANObjectCache.php(1729): CirrusSearch\BuildDocument\ParserOutputPageProperties->CirrusSearch\BuildDocument\{closure}(bool, int, array, null, array)
#7 /srv/mediawiki/php-1.43.0-wmf.19/includes/libs/objectcache/wancache/WANObjectCache.php(1559): WANObjectCache->fetchOrRegenerate(string, int, Closure, array, array)
#8 /srv/mediawiki/php-1.43.0-wmf.19/extensions/CirrusSearch/includes/BuildDocument/ParserOutputPageProperties.php(109): WANObjectCache->getWithSetCallback(string, int, Closure)
#9 /srv/mediawiki/php-1.43.0-wmf.19/extensions/CirrusSearch/includes/BuildDocument/ParserOutputPageProperties.php(51): CirrusSearch\BuildDocument\ParserOutputPageProperties->finalizeReal(Elastica\Document, WikiPage, CirrusSearch\CirrusSearch, MediaWiki\Revision\RevisionStoreRecord)
#10 /srv/mediawiki/php-1.43.0-wmf.19/extensions/CirrusSearch/includes/BuildDocument/BuildDocument.php(196): CirrusSearch\BuildDocument\ParserOutputPageProperties->finalize(Elastica\Document, MediaWiki\Title\Title, MediaWiki\Revision\RevisionStoreRecord)
#11 /srv/mediawiki/php-1.43.0-wmf.19/extensions/CirrusSearch/includes/Api/QueryBuildDocument.php(112): CirrusSearch\BuildDocument\BuildDocument->finalize(Elastica\Document, bool, MediaWiki\Revision\RevisionStoreRecord)
#12 /srv/mediawiki/php-1.43.0-wmf.19/includes/api/ApiQuery.php(711): CirrusSearch\Api\QueryBuildDocument->execute()
#13 /srv/mediawiki/php-1.43.0-wmf.19/includes/api/ApiMain.php(1948): ApiQuery->execute()
#14 /srv/mediawiki/php-1.43.0-wmf.19/includes/api/ApiMain.php(926): ApiMain->executeAction()
#15 /srv/mediawiki/php-1.43.0-wmf.19/includes/api/ApiMain.php(897): ApiMain->executeActionWithErrorHandling()
#16 /srv/mediawiki/php-1.43.0-wmf.19/includes/api/ApiEntryPoint.php(153): ApiMain->execute()
#17 /srv/mediawiki/php-1.43.0-wmf.19/includes/MediaWikiEntryPoint.php(200): MediaWiki\Api\ApiEntryPoint->execute()
#18 /srv/mediawiki/php-1.43.0-wmf.19/api.php(44): MediaWiki\MediaWikiEntryPoint->run()
#19 /srv/mediawiki/w/api.php(3): require(string)
#20 {main}
Impact

Low: Nine occurrences since first occurrence on 2024-08-01 (1.43.0-wmf.16)

Notes

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Renders fine (with an error message) at https://test.wikidata.org/w/index.php?curid=959:

image.png (1,365×340 px, 44 KB)

I guess some part of Wikibase (or WikibaseCirrusSearch?) forgot to account for the fact that the data and value type might not match somewhere.

@LucasWerkmeister : might this be related to current work on your side?

@Lucas_Werkmeister_WMDE :)

might this be related to current work on your side?

Hm, I doubt it (assuming current work refers to T375641), as I just noticed the task is three months old… I don’t think we had touched this code in August?

It’s probably due to Try looking up search index data formatters by data type – I guess we need to check if the data type and data value type match, using a DataTypeFactory, and return null if they’re different.

Moving out of the Radar column – IMHO this is for us to fix. Should be relatively simple too.

I haven’t tested it yet, but it’s probably possible to reproduce this by:

  1. creating a property with data type Time
  2. creating a statement with that property and a Time value
  3. commenting out the assertDataTypesCompatible() check in PropertyDataTypeChanger::changeDataType()
  4. using the repo/maintenance/changePropertyDataType.php maintenance script to change the data type of the property from Time to String
  5. getting WikibaseCirrusSearch to re-index the entity with the now-broken statement, using an API call similar to the one in T372993#10104381

As step 3 suggests, this is pretty much “this should never happen” territory, and it makes sense that the issue apparently only happens on Test Wikidata, not on real Wikidata. But given that this ends up in Logstash, we should still fix it.

karapayneWMDE subscribed.

removed from dev board until it goes through prioritization pipeline

ItamarWMDE renamed this task from TypeError: Argument 1 passed to Wikimedia\Services\ServiceContainer::{closure}() must be an instance of DataValues\StringValue, instance of DataValues\TimeValue given, called in extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php:177 to [SW] TypeError: Argument 1 passed to Wikimedia\Services\ServiceContainer::{closure}() must be an instance of DataValues\StringValue, instance of DataValues\TimeValue given, called in extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php:177.Dec 17 2024, 12:02 PM
ItamarWMDE renamed this task from [SW] TypeError: Argument 1 passed to Wikimedia\Services\ServiceContainer::{closure}() must be an instance of DataValues\StringValue, instance of DataValues\TimeValue given, called in extensions/WikibaseCirrusSearch/src/Fields/StatementsField.php:177 to Resolve type errors caused by data type changes in test Wikidata .Dec 18 2024, 10:32 AM
ItamarWMDE updated the task description. (Show Details)

Removing Search Platform, we expect the work to be tracked by WMDE

hoo removed hoo as the assignee of this task.Jan 31 2025, 8:52 PM
hoo subscribed.

Unassigning myself, won't be able to look into this before Tuesday.

Change #1116835 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseCirrusSearch@master] WIP: StatementsField: Check data type and data value type

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

Change #1116841 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseCirrusSearch@master] WIP: Inject DataTypeFactory into StatementsField

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

Change #1116842 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseCirrusSearch@master] WIP: Clean up StatementProviderFieldDefinitions compatibility

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

Change #1117196 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseMediaInfo@master] Temporarily skip test for CI

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

Change #1117197 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseMediaInfo@master] Update for WikibaseCirrusSearch changes

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

Change #1117198 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseLexemeCirrusSearch@master] Update for WikibaseCirrusSearch changes

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

Change #1116841 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/WikibaseCirrusSearch@master] WIP: Inject DataTypeFactory into StatementsField

Reason:

squashed into parent change

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

Change #1117196 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Temporarily skip tests for CI

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

Change #1116835 merged by jenkins-bot:

[mediawiki/extensions/WikibaseCirrusSearch@master] StatementsField: Check data type and data value type

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

Change #1117197 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Update for WikibaseCirrusSearch changes

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

Change #1117198 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexemeCirrusSearch@master] Update for WikibaseCirrusSearch changes

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

Change #1116842 merged by jenkins-bot:

[mediawiki/extensions/WikibaseCirrusSearch@master] Clean up StatementProviderFieldDefinitions compatibility

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

IMHO this isn’t remotely feasible to backport, so let’s let it roll out with the train and see if it’s fixed next week.

Lucas_Werkmeister_WMDE claimed this task.

For some reason, the error already disappeared from logstash in December as far as I can see (Logstash link):

image.png (1,360×300 px, 22 KB)

I’m guessing this means CirrusSearch stopped trying to reindex the affected pages? But be that as it may, we can open the two request URLs found in Logstash manually:

And they both work without errors now, so let’s call this resolved \o/