Page MenuHomePhabricator

PUT /w/rest.php/v1/page fails with HTTP 409 when there's no conflict
Open, Needs TriagePublic

Description

tl;dr: MediaWiki\Rest\Handler\EditHandler::mapActionModuleResult transforms any non-Success into HTTP 409.


The following REST API request tries to add {{Object location|51.48305|-0.25}}, but fails with HTTP 409.

await fetch("https://commons.wikimedia.beta.wmflabs.org/w/rest.php/v1/page/File:Test%20153.jpg", {
    "credentials": "include",
    "headers": {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11.1; rv:85.0) Gecko/20100101 Firefox/85.0",
        "Accept": "*/*",
        "Accept-Language": "en-US,en;q=0.5",
        "Authorization": "Bearer xxx",
        "Content-Type": "application/json"
    },
    "referrer": "http://localhost:8184/",
    "body": "{\"source\":\"== {{int:filedesc}} ==\\n{{Information\\n|description={{en|1=this is test}}, {{fr|1=c'est un test}}\\n|source={{own}}\\n|author=[[User:Maxbetton|Maxbetton]]\\n|date={{According to Exif data|2021-01-22}}\\n}}\\n{{Object location|51.48305|-0.25}}\\n\\n{{Location|51.48494|-0.24882}}\\n\\n== {{int:license-header}} ==\\n{{self|cc-by-sa-4.0}}\\n\\n{{Uploaded from Mobile|platform=Android|version=3.0.0-debug-issue-2810-Option_to_remove_a_new_language_description_while_uploading~bad65e3e1}}\\n{{Uncategorized|year=2021|month=January|day=22}}\",\"comment\":\"{{Object location}}\",\"latest\":{\"id\":229701,\"timestamp\":\"2021-01-31T22:57:00Z\"}}",
    "method": "PUT",
    "mode": "cors"
});

According to https://www.mediawiki.org/wiki/API:REST_API/Reference#Update_page this would imply that the specified latest.id refers to an outdated revision. However, I've obtained this latest.id immediately before from https://commons.wikimedia.beta.wmflabs.org/w/rest.php/v1/page/File:Test%20153.jpg

await fetch("https://commons.wikimedia.beta.wmflabs.org/w/rest.php/v1/page/File:Test%20153.jpg", {
    "credentials": "omit",
    "headers": {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11.1; rv:85.0) Gecko/20100101 Firefox/85.0",
        "Accept": "*/*",
        "Accept-Language": "en-US,en;q=0.5"
    },
    "referrer": "http://localhost:8184/",
    "method": "GET",
    "mode": "cors"
});

// =>

{
	"id": 102379,
	"key": "File:Test_153.jpg",
	"title": "File:Test 153.jpg",
	"latest": {
		"id": 229701,
		"timestamp": "2021-01-31T22:57:00Z"
	},
	"content_model": "wikitext",
	"license": {
		"url": "//creativecommons.org/licenses/by-sa/3.0/",
		"title": "Creative Commons Attribution-Share Alike 3.0"
	},
	"source": "== {{int:filedesc}} ==\n{{Information\n|description={{en|1=this is test}}, {{fr|1=c'est un test}}\n|source={{own}}\n|author=[[User:Maxbetton|Maxbetton]]\n|date={{According to Exif data|2021-01-22}}\n}}\n{{Location|51.48494|-0.24882}}\n\n== {{int:license-header}} ==\n{{self|cc-by-sa-4.0}}\n\n{{Uploaded from Mobile|platform=Android|version=3.0.0-debug-issue-2810-Option_to_remove_a_new_language_description_while_uploading~bad65e3e1}}\n{{Uncategorized|year=2021|month=January|day=22}}"
}

When attempting to perform the edit manually, I was prompted to enter a CAPTCHA presumably due to https://commons.wikimedia.beta.wmflabs.org/wiki/Template:Object_location containing four external links.


It seems that the following code is any non Success result in a HTTP 409 Conflict -- https://github.com/wikimedia/mediawiki/blob/264adbdf49413054a10a6e39311b8b0ede715e49/includes/Rest/Handler/EditHandler.php#L90-L94

This leaves API consumers puzzled and hides the underlying problem of the failed edit.

Event Timeline

Aklapper added a subscriber: daniel.

@daniel: Removing task assignee as this open task has been assigned for more than two years - See the email sent to task assignee on Feburary 22nd, 2023.
Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome! :)
If this task has been resolved in the meantime, or should not be worked on by anybody ("declined"), please update its task status via "Add Action… 🡒 Change Status".
Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator. Thanks!