addAttachment() with empty data crashes with HTTP Error 400: Bad Request

Bug #353784 reported by Martin Pitt
2
Affects Status Importance Assigned to Milestone
launchpadlib
Invalid
Undecided
Unassigned

Bug Description

The apport retracer just crashed with

Traceback (most recent call last):
  File "/tmp/tmpwVg4WG/usr/bin/apport-retrace", line 569, in <module>
    crashdb.update(crashid, report)
  File "/usr/lib/python2.6/dist-packages/apport/crashdb_impl/launchpad.py", line 270, in update
    is_patch=False)
  File "/usr/lib/python2.6/dist-packages/launchpadlib/resource.py", line 349, in __call__
    url, in_representation, http_method, extra_headers=extra_headers)
  File "/usr/lib/python2.6/dist-packages/launchpadlib/_browser.py", line 212, in _request
    raise HTTPError(response, content)
launchpadlib.errors.HTTPError: HTTP Error 400: Bad Request

when it tried to do this:

        bug.addAttachment(comment='',
                #content_type=?
                data=report['ThreadStacktrace'],
                description='ThreadStacktrace.txt (retraced)',
                filename='ThreadStacktrace.txt',
                is_patch=False)

(For my own record and reproduction: this happens on 353707).

What condition causes this error? I've seen it work fine on other bugs, so I don't think there's something generally wrong with the code.

Revision history for this message
Martin Pitt (pitti) wrote : Re: addAttachment() crashes with HTTP Error 400: Bad Request for empty files

Ah, got it. It happens if data is empty. Reproducible on staging with

>>> b=lp.bugs[89040]
>>> b.addAttachment(comment='', data='', description='ThreadStacktrace.txt (retraced)', filename='ThreadStacktrace.txt', is_patch=False)

I'll work around this in apport.

summary: - addAttachment() crashes with HTTP Error 400: Bad Request
+ addAttachment() crashes with HTTP Error 400: Bad Request for empty files
Changed in launchpadlib:
status: New → Confirmed
Martin Pitt (pitti)
summary: - addAttachment() crashes with HTTP Error 400: Bad Request for empty files
+ addAttachment() with empty data crashes with HTTP Error 400: Bad Request
Revision history for this message
Leonard Richardson (leonardr) wrote :

I don't consider this is a crash. Launchpad sent an error condition, with launchpadlib treats as an exceptional occurance. If you look at the 'content' attribute of the error you'll see this:

data: Cannot upload empty file.

Which accurately diagnoses the problem. This looks like launchpad sending an error and launchpadlib handling it as designed.

Revision history for this message
Leonard Richardson (leonardr) wrote :

Do you think you should be allowed to upload a zero-byte file? If so, reopen this bug and change 'affects' to malone. This error checking occurs in validators/bugattachment.py and is tested in doc/bugattachments.txt

Changed in launchpadlib:
status: Confirmed → Invalid
Revision history for this message
Martin Pitt (pitti) wrote :

Ah, I didn't see the content field of the error message (can it become part of the exception string?). I agree that it makes sense to disallow 0-byte uploads, it just had saved me a lot of time if the error message was clearer. Thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.