Page MenuHomePhabricator

UploadError is not thrown to the client code when some warnings are ignored
Open, Needs TriagePublicBUG REPORT

Description

Try to upload a duplicate of [[:ro:File:Fotoliu_(Artă_decorativă)_2784_11.10.2017_Fond_8764B28DD6F748CC984A8365A6CA66CF.jpg]], using the "Foto" prefix for the duplicate file, so it triggers the bad-prefix warning. In order for the upload to happen, I'm ignoring the bad-prefix warning, as shown by the (simplified) code below:

try:
	success = imagepage.upload("/path/to/file",
				ignore_warnings=['bad-prefix'],
                                chunk_size=0,
                                _file_key=None, _offset=0,
                                comment="Imagine Cimec nouă")
except pywikibot.exceptions.APIError as error:
        if error.code == 'bad-prefix':
	    pywikibot.error('Upload error: Bad-prefix')
        elif error.code == 'duplicate':
            pywikibot.error('Upload error: Duplicate')
       return
except Exception:
	pywikibot.error('Upload error: ', exc_info=True)
        return

if success:
	pywikibot.output('Success')
else:
	pywikibot.output('Upload aborted.')

The actual output is:

[UploadError("duplicate", "Uploaded file is a duplicate of ['Fotoliu_(Artă_decorativă)_2784_11.10.2017_Fond_8764B28DD6F748CC984A8365A6CA66CF.jpg'].", {}), UploadError("bad-prefix", "Target filename has a bad prefix Fotoliu_(Artă_decorativă)_2784_11.10.2017_Fond_A8C631B7BB4A4D8CB3DD2DE4B52A21B0.jpg.", {})]
Upload aborted.

Expected output would be to have the unignored error thrown to the user code:

[UploadError("duplicate", "Uploaded file is a duplicate of ['Fotoliu_(Artă_decorativă)_2784_11.10.2017_Fond_8764B28DD6F748CC984A8365A6CA66CF.jpg'].", {}), UploadError("bad-prefix", "Target filename has a bad prefix Fotoliu_(Artă_decorativă)_2784_11.10.2017_Fond_A8C631B7BB4A4D8CB3DD2DE4B52A21B0.jpg.", {})]
Upload error: Duplicate

Event Timeline

Seems there is a mess with ignore_warnings and report_success parameters.

I agree, it would have been preferable if the change in semantics came through a rename of parameters instead.