I’m working on a tool to add and remove categories from pages. When implementing the edit via API, I tried to do “the right thing” so that edit conflicts would be detected; however, when I tried it out just now, this doesn’t seem to work, and my tool will overwrite whatever changes were made between it fetching the page and sending the edited version, with no warning.
You can see the source code on GitHub; in a nutshell, the actions I use are:
-
action=query
,prop=revisions
,rvprop=ids|content|contentmodel|timestamp
,rvslots=main
,curtimestamp=1
, to get the wikitext to edit as well as timestamps for use below -
action=edit
,basetimestamp=…
,starttimestamp=…
, where both timestamps come from the previous API request
I tested it by inserting a time.sleep(30)
on line 60, between the two API requests, and then manually editing the page during that time. But no matter what I do to the Wikitext – touching almost every line or even completely blanking the page – the action=edit
request will not raise an error, and instead overwrite the changes that happened in between. The oldrevid
of the edit returned by the API also does not match the original revision ID of the edit that the bot edit is actually based on (corresponding to the basetimestamp
argument), but rather the revision ID of the manual edit I made in between.
I know the timestamps I’m sending aren’t None
or anything trivial like that – here they are printed:
{'basetimestamp': '2019-03-12T23:55:49Z', 'starttimestamp': '2019-03-12T23:55:49Z'}
(In this case they’re identical because of the “setup” edit that is made right before the actual test starts. At other times they’re one second apart, with basetimestamp
< starttimestamp
.)
I also checked the parameter names – I’m pretty sure I’m not misspelling them. And just one time I did get an edit conflict, though I don’t know what exactly I did – since I didn’t have all my windows at the same time, I don’t know in what order things happened. (But you can see that there’s no QuickCategories edit after this edit.) And yet, most of the time MediaWiki seems to be ignoring those timestamps.
There are some existing Phabricator tasks for failure to detect edit conflicts, but all of them sound hard to reproduce and most of them seem to involve specific conditions as well that aren’t in place here. (Also, all of them seem to concern interactive editing, not editing via the API.) This case, on the other hand, seems to be reliably reproducible, so I suspect the error lies with me and not with MediaWiki. Does anyone see something I’m doing wrong?