Page MenuHomePhabricator

[LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations()
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations()
exception.trace
from /srv/mediawiki/php-1.41.0-wmf.13/extensions/WikibaseLexeme/src/Presentation/Formatters/FormIdTextFormatter.php(57)
#0 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/EntityIdValueFormatter.php(44): Wikibase\Lexeme\Presentation\Formatters\FormIdTextFormatter->formatEntityId(Wikibase\DataModel\Entity\ItemId)
#1 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/DispatchingValueFormatter.php(72): Wikibase\Lib\Formatters\EntityIdValueFormatter->format(Wikibase\DataModel\Entity\EntityIdValue)
#2 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/PropertyValueSnakFormatter.php(148): Wikibase\Lib\Formatters\DispatchingValueFormatter->formatValue(Wikibase\DataModel\Entity\EntityIdValue, string)
#3 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/PropertyValueSnakFormatter.php(117): Wikibase\Lib\Formatters\PropertyValueSnakFormatter->formatValue(Wikibase\DataModel\Entity\EntityIdValue, string)
#4 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/DispatchingSnakFormatter.php(150): Wikibase\Lib\Formatters\PropertyValueSnakFormatter->formatSnak(Wikibase\DataModel\Snak\PropertyValueSnak)
#5 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/lib/includes/Formatters/ErrorHandlingSnakFormatter.php(68): Wikibase\Lib\Formatters\DispatchingSnakFormatter->formatSnak(Wikibase\DataModel\Snak\PropertyValueSnak)
#6 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(177): Wikibase\Lib\Formatters\ErrorHandlingSnakFormatter->formatSnak(Wikibase\DataModel\Snak\PropertyValueSnak)
#7 /srv/mediawiki/php-1.41.0-wmf.13/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(145): Wikibase\Repo\Api\FormatSnakValue->formatValue(array, Wikibase\DataModel\Entity\EntityIdValue, NULL)
#8 /srv/mediawiki/php-1.41.0-wmf.13/includes/api/ApiMain.php(1913): Wikibase\Repo\Api\FormatSnakValue->execute()
#9 /srv/mediawiki/php-1.41.0-wmf.13/includes/api/ApiMain.php(890): ApiMain->executeAction()
#10 /srv/mediawiki/php-1.41.0-wmf.13/includes/api/ApiMain.php(861): ApiMain->executeActionWithErrorHandling()
#11 /srv/mediawiki/php-1.41.0-wmf.13/api.php(95): ApiMain->execute()
#12 /srv/mediawiki/php-1.41.0-wmf.13/api.php(48): wfApiMain()
#13 /srv/mediawiki/w/api.php(3): require(string)
#14 {main}
Impact

Minimal. An invalid request with no sensible interpretation can be used to trigger logspam. Only one actual occurrence in logstash.

Notes

The decoded request URL is:

In other words, someone’s formatting an item ID value with a property that’s intended for form IDs, hence the type error. The formatter just needs to handle this a bit more carefully (producing a better error when the given value doesn’t look as expected).
A similar exception was previously seen in CI: T201988: FormIdHtmlFormatter: Call to undefined method Item::getRepresentations()

Details

Request URL
https://www.wikidata.org/w/api.php?action=wbformatvalue&datavalue=%7B%22value%22%3A%7B%22id%22%3A%22Q96%22%7D%2C%22type%22%3A%22wikibase-entityid%22%7D&errorformat=plaintext&format=json&generate=text%2Fplain&options=%7B%22lang%22%3A%22en%22%7D&property=P5193&uselang=en
Related Changes in Gerrit:

Event Timeline

SenseIdTextFormatter almost certainly has the same bug, and we should also check FormIdHtmlFormatter and SenseIdHtmlFormatter.

ItamarWMDE renamed this task from Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations() to [LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations().Nov 8 2023, 10:50 AM
ItamarWMDE moved this task from Incoming to [DOT] By Project on the wmde-wikidata-tech board.

Prio Notes

Impact AreaAffected
production / end usersyes
monitoringno
development effortsno
onboarding effortsno
additional stakeholdersmaybe
ItamarWMDE renamed this task from [LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations() to [SW] [LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations().Nov 21 2023, 4:01 PM
ItamarWMDE renamed this task from [SW] [LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations() to [LEX] Error: Call to undefined method Wikibase\DataModel\Entity\Item::getRepresentations().Dec 6 2023, 10:20 AM

For the record, I just opened the request ID of this task again, reqId 0aec1cd0-d4fb-440d-bb84-83ec8505603d. It’s still reproducible.

It doesn’t look like we have a good example for how this kind of bad request ought to be handled. If you try to format an item ID using a property with data type “property”, or format a property ID using a property with data type “item”, you just got a fully formatted link to the item / property back, with its label and everything – evidently they’re compatible enough that it just works out. If you try to format a lexeme ID using properties with data type “item” or “property”, you get a link to the lexeme with the lexeme ID as link text (the label lookup probably returns no label, but without an error). But looking at FormatSnakValue, throwing a FormattingException seems like a good guess for what the formatter should do.

Change 994150 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@master] Ensure Entity is Form in FormIdTextFormatter

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

Change 994156 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/WikibaseLexeme@master] Check entity type in Form and Sense formatters

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

Change 994156 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexeme@master] Check entity type in Form and Sense formatters

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

Change 994150 abandoned by Arthur taylor:

[mediawiki/extensions/Wikibase@master] Check entity type in Form / Sense Formatters

Reason:

Tests included in another patch

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