Zhuyifei1999 has uploaded a new change for review. ( 
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, 23 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/21/334421/1

diff --git a/pywikibot/site.py b/pywikibot/site.py
index f2724d9..abeb470 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6095,6 +6095,29 @@
                             # TODO: catch and process foreseeable errors
                             if error.code == u'uploaddisabled':
                                 self._uploaddisabled = True
+                            elif error.code == u'stashfailed':
+                                # TODO: Ask MediaWiki to change this
+                                # ambiguous error code.
+                                if 'offset' in error.other:
+                                    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

-- 
To view, visit https://gerrit.wikimedia.org/r/334421
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I78fff13769e887ce554e8acf8664b1ce8e8bb5f5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Zhuyifei1999 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to