Edgewall Software

Opened 7 years ago

Closed 7 years ago

#12369 closed defect (fixed)

KeyError: 'attachment'

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.11
Component: attachment Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Attachment upload POST request without an attachment raises a TracError rather than a KeyError.

API Changes:
Internal Changes:


From the logs:

2016-02-09 23:59:35,811 Trac[main] ERROR: Internal Server Error: <RequestWithSession "POST '/attachment/wiki/space ship/?action=new'">, referrer None
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.0-stable/lib/python2.7/site-packages/trac/web/main.py", line 554, in _dispatch_request
  File "/usr/local/virtualenv/1.0-stable/lib/python2.7/site-packages/trac/web/main.py", line 247, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/virtualenv/1.0-stable/lib/python2.7/site-packages/trac/attachment.py", line 529, in process_request
    data = self._do_save(req, attachment)
  File "/usr/local/virtualenv/1.0-stable/lib/python2.7/site-packages/trac/attachment.py", line 706, in _do_save
    upload = req.args['attachment']
KeyError: 'attachment'

Attachments (0)

Change History (4)

comment:1 by Ryan J Ollos, 7 years ago

Owner: set to Ryan J Ollos
Status: newassigned

I can reproduce the issue using curl:

$curl -c cookie http://localhost:8000/attachment/wiki/WikiStart
$curl -v -b cookie --form action=new --form __FORM_TOKEN=771659fefe870878a683def2 http://localhost:8000/attachment/wiki/WikiStart

Proposed change:

  • trac/attachment.py

    $git diff
    diff --git a/trac/attachment.py b/trac/attachment.py
    index 4c67486..96c7bc6 100644
    a b class AttachmentModule(Component):  
    708708        if 'cancel' in req.args:
    709709            req.redirect(get_resource_url(self.env, parent_resource, req.href))
    711         upload = req.args['attachment']
    712         if not hasattr(upload, 'filename') or not upload.filename:
     711        upload = req.args.get('attachment')
     712        if not upload or not hasattr(upload, 'filename') \
     713                or not upload.filename:
    713714            raise TracError(_('No file uploaded'))
    714715        if hasattr(upload.file, 'fileno'):
    715716            size = os.fstat(upload.file.fileno())[6]

I'll add a test case.

comment:2 by Jun Omae, 7 years ago

I think we should use req.args.getfirst('attachment') instead.

comment:3 by Ryan J Ollos, 7 years ago

Release Notes: modified (diff)

That sounds good. I'll implement that change.

comment:4 by Ryan J Ollos, 7 years ago

Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [14581], merged to trunk in [14582:14583].

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.