Page MenuHomePhabricator

Some ApiParse requests fail due to fatal MWException: "not supported for content model"
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

Request ID: W6M@7grAMG8AAAerQtQAAABL
Request: GET, /w/api.php?...prop=wikitext..&contentformat=text/plain

exception
MWException: Format text/plain is not supported for content model wikitext

#0 /srv/mediawiki/php-1.32.0-wmf.20/includes/content/TextContentHandler.php(46): ContentHandler->checkFormat(string)
#1 /srv/mediawiki/php-1.32.0-wmf.20/includes/content/AbstractContent.php(155): TextContentHandler->serializeContent(WikitextContent, string)
#2 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiParse.php(463): AbstractContent->serialize(string)
#3 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(1587): ApiParse->execute()
#4 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(531): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.32.0-wmf.20/api.php(87): ApiMain->execute()
#7 /srv/mediawiki/w/api.php(3): include(string)

Notes

API request fatal rate is increased due to this issue.

It appears that this is a matter of a certain feature not being available yet, or intentionally not provided. That's probably fine, at least in the short-term, but it needs to not crash the request to avoid false alarms. As a stop-gap solution it can probably be caught somewhere along the way and simply reject explicitly so as to mark it a user error (rather than server error).

Related:

Related Objects

StatusSubtypeAssignedTask
Declineddchen
OpenNone
OpenNone
DuplicateNone
OpenFeatureNone
OpenBUG REPORTNone
OpenNone
StalledNone
OpenFeatureNone
DuplicateNone
ResolvedNone
OpenNone
OpenNone
OpenFeatureNone
OpenNone
ResolvedNone
ResolvedNone
OpenFeatureNone
OpenNone
OpenFeatureNone
StalledNone
OpenNone
OpenNone
OpenNone
ResolvedPRODUCTION ERRORFunc

Event Timeline

Anomie subscribed.

What seems to be going on is that it's using a content format intended for interpretation of input text (of which there isn't any in that request) to try and format the output. It looks like ApiEditPage likely has the same issue.

The direct solution would be to remove the passing of a format when calling Content->serialize(). But since both of these modules are going to need some major work soon for MCR anyway, I'm probably not going to bother doing that as a separate patch.

Recently triggered via urls such as https://en.wikipedia.org/w/api.php?action=parse&page=Example&contentformat=application/json&prop=wikitext&section=2.

Suppressing in Logstash/new-errors is difficult due the message not having a normal form without variance by user input, and the exception file/line of TextContentHandler.php(46) is too wide.

Using ApiParse.php(463): AbstractContent->serialize(string) for now, seems to be the most specific, whilst still potentially ignoring other errors in the same kind of API call.

Krinkle renamed this task from Some ApiParse reqs fatal due to contentformat to Some ApiParse requests fail due to fatal MWException: "not supported for content model".Nov 4 2018, 8:44 PM
Krinkle added a project: Platform Engineering.

Still seen in the logs for 1.33-wmf.1. Stack trace changed, hence it resurfaced. Exposed from the same urls as T206253#4672796.

MWException: Format text/javascript is not supported for content model wikitext

#0 /srv/mediawiki/php-1.33.0-wmf.1/includes/content/TextContentHandler.php(116): ContentHandler->checkFormat(string)
#1 /srv/mediawiki/php-1.33.0-wmf.1/includes/content/ContentHandler.php(145): TextContentHandler->unserializeContent(string, string)
#2 /srv/mediawiki/php-1.33.0-wmf.1/includes/api/ApiParse.php(222): ContentHandler::makeContent(string, Title, string, string)
#3 /srv/mediawiki/php-1.33.0-wmf.1/includes/api/ApiMain.php(1570): ApiParse->execute()
#4 /srv/mediawiki/php-1.33.0-wmf.1/includes/api/ApiMain.php(531): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.33.0-wmf.1/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.33.0-wmf.1/api.php(87): ApiMain->execute()
#7 /srv/mediawiki/w/api.php(3): include(string)
mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:08 PM

Still seen in Logstash.

It's trivial to fix I believe, if someone is committing to review patch for that

Aklapper changed the task status from Stalled to Open.Oct 19 2020, 4:34 PM

The previous comments don't explain who or what (task?) exactly this task is stalled on ("If a report is waiting for further input (e.g. from its reporter or a third party) and can currently not be acted on"). Hence resetting task status.

(Smallprint, as general orientation for task management: If you wanted to express that nobody is currently working on this task, then the assignee should be removed and/or priority could be lowered instead. If work on this task is blocked by another task, then that other task should be added via Edit Related Tasks...Edit Subtasks. If this task is stalled on an upstream project, then the Upstream tag should be added. If this task requires info from the task reporter, then there should be instructions which info is needed. If this task needs retesting, then the TestMe tag should be added. If this task is either out of scope and nobody should ever work on this, or nobody else managed to reproduce the problem described in this task, then this task should have the "Declined" status. If the task is valid but should not appear on some team's workboard, then the team project tag should be removed while the task has another active project tag.)

Platform team: I'm moving this back to request re-triage as it is still a current issue. Feel free to undo. (It seemed like it may've been unintentional to move an active production error to an icebox?)

Change 766322 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] ApiParse: Fail gracefully when the requested format is not supported

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

Change 766563 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] Throw MWContentSerializationException instead of normal MWException

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

Change 766563 abandoned by Func:

[mediawiki/core@master] content: Throw MWContentSerializationException instead of normal MWException when asserting format

Reason:

per comment

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

Change 767799 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] ApiParse: Ignore contentmodel param when the query is based on page

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

Change 766322 merged by jenkins-bot:

[mediawiki/core@master] ApiParse: Fail gracefully when the requested format is not supported

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

Change 767799 merged by jenkins-bot:

[mediawiki/core@master] ApiParse: Ignore 'contentformat' param when the query is based on page

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

Umherirrender assigned this task to Func.

Technical the last patch set was a breaking change for an undocumented feature. The parameter contentformat is documented as "Content serialization format used for the input text. Only valid when used with text.", but the format was also applied for non-text parses like page=. Such transformation can only happen for ContentHandler with two or more formats. Core does not have such a ContentHandler, but Wikibase.

At the moment requests like shows the format change
https://www.wikidata.org/w/api.php?action=parse&page=Property:P31&prop=wikitext&contentformat=application/vnd.php.serialized
https://www.wikidata.org/w/api.php?action=parse&page=Property:P31&prop=wikitext&contentformat=application/json

While invalid formats are still failing
https://www.wikidata.org/w/api.php?action=parse&page=Property:P31&prop=wikitext&contentformat=text/unknown

With the patch set all requests returning the same result, which is identical as requested without the parameter
https://www.wikidata.org/w/api.php?action=parse&page=Property:P31&prop=wikitext

As replacement it seems prop=revision with the contentformat is usable.

I just want to write it down, but I think there is no need for clarification. Requesting the content of wikidata item as wikitext seems like a bad use case.

This also broke a documented (and used) feature of ProofreadPage, where the fields of an Index namespace page can be serialised as JSON.

Documentation of the broken feature: https://www.mediawiki.org/wiki/Extension:ProofreadPage/Index_data_API

Issue for the breakage: T321446