Page MenuHomePhabricator

ReadOnlyError makes bot crash with incorrect editconflict
Closed, ResolvedPublic

Description

When running a bot I seem to run into this situation about once a day:

Adding instance claim to [[wikidata:Q592478]]
Adding new reference claim to [[wikidata:Q592478]]
ERROR: Detected MediaWiki API exception ReadOnlyError; retrying
WARNING: Waiting 5 seconds before retrying.
Traceback (most recent call last):
  File "C:\pywikibot\coredev\viaf_import.py", line 445, in <module>
    main()
  File "C:\pywikibot\coredev\viaf_import.py", line 440, in main
    viafBot.run()
  File "C:\pywikibot\coredev\viaf_import.py", line 85, in run
    self.addOtherRegistries(personItem, viafid, regdict)
  File "C:\pywikibot\coredev\viaf_import.py", line 104, in addOtherRegistries
    self.addViafReference(personItem, newclaim, viafid)
  File "C:\pywikibot\coredev\viaf_import.py", line 317, in addViafReference
    newclaim.addSources([refstated, refurl, refdate])
  File "C:\pywikibot\coredev\pywikibot\page.py", line 3881, in addSources
    data = self.repo.editSource(self, claims, new=True, **kwargs)
  File "C:\pywikibot\coredev\pywikibot\site.py", line 987, in callee
    return fn(self, *args, **kwargs)
  File "C:\pywikibot\coredev\pywikibot\site.py", line 5369, in editSource
    data = req.submit()
  File "C:\pywikibot\coredev\pywikibot\data\api.py", line 1071, in submit
    raise APIError(code, info, **result["error"])
pywikibot.data.api.APIError: editconflict: Edit conflict.
<class 'pywikibot.data.api.APIError'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort
  • Bot adds claim (no problem)
  • Bot adds reference
  • Runs into a ReadOnlyError
  • Tries again
  • Editconflict

It's a bit weird because it looks like at https://www.wikidata.org/w/index.php?title=Q592478&action=history the reference was added in the first step.

I'll file another bug for the frequent MediaWiki switching to read-only problems. I also encountered that as a user.

Event Timeline

Multichill raised the priority of this task from to Needs Triage.
Multichill updated the task description. (Show Details)
Multichill subscribed.

My immediate workaround is for you to revise your code to add the references as part of the same operation.

Use ItemPage.get(), then alter the ItemPage contents (i.e. add Claims directly to item.claims), and then save it with Page.editEntity()
One editentities API call; one edit; no edit conflicts. See tests/wikibase_edit_tests.py test_edit_entity*

Also see https://gerrit.wikimedia.org/r/#/c/176934/ which makes it easier to add Claims to the ItemPage.

jayvdb set Security to None.

Oh, wrong bug. Moving this to the other one

As a "normal" user I had this also on the Dutch Wikipedia. Akoopal had the same and he managed to dig up the timestamp:
2014-12-21 22:51:46 akoopal : "Opgelet: De database is op dit moment wegens onderhoudswerkzaamheden geblokkeerd." This is the message we have at https://nl.wikipedia.org/wiki/MediaWiki:Readonlywarning

Why this log has editconflict and readonly codes at the same time ? editconflict is the old name ?

I suppose that the problem is solved with T154011: Manage temporary readonly error ? @Multichill ?

Multichill claimed this task.

3 years old, haven't seen it in the last year, probably fixed.