jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/334421 )
Change subject: site: Handle offset mismatches during chunked upload ......................................................................
site: Handle offset mismatches during chunked upload
If the server returns an error code of 'stashfailed', error JSON contains an offset, and the provided offset is different from the offset we have sent it, we believe the server refuse to accept this chunk because of offset mismatch.
A condition is added to APIError handling so that if such error is encountered, we update our own offset and continue the upload.
Bug: T156402 Change-Id: I78fff13769e887ce554e8acf8664b1ce8e8bb5f5 --- M pywikibot/site.py 1 file changed, 24 insertions(+), 0 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/pywikibot/site.py b/pywikibot/site.py index f2724d9..24434a5 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -6095,6 +6095,30 @@ # TODO: catch and process foreseeable errors if error.code == u'uploaddisabled': self._uploaddisabled = True + elif error.code == u'stashfailed' and \ + 'offset' in error.other: + # TODO: Ask MediaWiki to change this + # ambiguous error code. + + new_offset = int(error.other['offset']) + # If the offset returned from the server + # (the offset it expects now) is equal to + # the offset we sent it, there must be + # something else that prevented the upload, + # instead of simple offset mismatch. This + # also prevents infinite loops when we + # upload the same chunk again and again, + # every time ApiError. + if offset != new_offset: + pywikibot.log('Old offset: {0}; Returned ' + 'offset: {1}; Chunk size: ' + '{2}'.format(offset, new_offset, + len(chunk))) + pywikibot.warning('Attempting to correct ' + 'automatically from ' + 'offset mismatch error.') + offset = new_offset + continue raise error if 'nochange' in data: # in simulation mode break
pywikibot-commits@lists.wikimedia.org