Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#12060 closed defect (fixed)

Traceback in logs resulting in "KeyError: 1"

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: low Milestone: 1.0.9
Component: ticket system Version: 0.12-stable
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed: viewing an invalid comment version raises a KeyError. The most recent comment version is now displayed.

API Changes:
Internal Changes:

Description

I've been seeing issues like the following in the logs, with near daily occurrences. I haven't tried to reproduce yet. It could just be another case of bots inputing invalid data, but it would be good to avoid the traceback.

2015-05-06 17:11:27,781 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/main.py", line 513, in _dispatch_request
    dispatcher.dispatch(req)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/main.py", line 241, in dispatch
    content_type)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/chrome.py", line 1096, in render_template
    encoding='utf-8')
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 183, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 58, in encode
    for chunk in iterator:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 339, in __call__
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 826, in __call__
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 670, in __call__
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 771, in __call__    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/output.py", line 586, in __call__
    for ev in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/chrome.py", line 1266, in _strip_accesskeys
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/web/chrome.py", line 1255, in _generate
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/filters/transform.py", line 686, in _unmark
    for mark, event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/filters/transform.py", line 1081, in __call__
    for mark, event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/filters/transform.py", line 117, in __iter__
    event = self.stream.next()
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/filters/transform.py", line 714, in __call__
    for mark, event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/filters/transform.py", line 682, in _mark
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 605, in _include
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-lin
ux-i686.egg/genshi/template/markup.py", line 327, in _match
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 545, in _flatten
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/path.py", line 588, in _generate
    subevent = next()
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 605, in _include
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/markup.py", line 316, in _strip
    event = next()
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 545, in _flatten
    for kind, data, pos in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/core.py", line 288, in _ensure
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/path.py", line 588, in _generate
    subevent = next()
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 605, in _include
    for event in stream:
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/markup.py", line 316, in _strip
    event = next()
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 565, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/base.py", line 277, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/eval.py", line 178, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Trac-1.0.5-py2.6.egg/trac/ticket/templates/ticket_change.html", line 138, in <Expression u'wiki_to_html(context, change.comment_history[int(cversion)].comment, escape_newlines=preserve_newlines)'>
    ${wiki_to_html(context, change.comment_history[int(cversion)].comment, escape_newlines=preserve_newlines)}
  File "/srv/trac-hacks.org/pve/lib/python2.6/site-packages/Genshi-0.6-py2.6-linux-i686.egg/genshi/template/eval.py", line 333, in lookup_item
    return obj[key]
KeyError: 1

Attachments (0)

Change History (8)

comment:1 by Jun Omae, 5 years ago

Component: generalticket system
Milestone: next-stable-1.0.x
Version: 0.12-stable

Reproduced with Trac 0.12.6 and 1.0.5.

  1. Create a new ticket
  2. Add a comment to the ticket
  3. Visit /ticket/<id>?cversion=1&cnum_hist=1 with id of the ticket

comment:2 by Ryan J Ollos, 5 years ago

Milestone: next-stable-1.0.x1.0.7
Owner: set to Ryan J Ollos
Priority: normallow
Status: newassigned

comment:3 by Ryan J Ollos, 5 years ago

Milestone: 1.0.71.2

comment:4 by Ryan J Ollos, 5 years ago

I propose the following fix, which I would add a functional test for.

  • trac/ticket/templates/ticket_change.html

    diff --git a/trac/ticket/templates/ticket_change.html b/trac/ticket/templates/ticket_change.html
    index 27ad18b..a93c457 100644
    a b Arguments:  
    3333               show_editor = can_edit_comment and str(cnum) == cnum_edit;
    3434               show_history = str(cnum) == cnum_hist;
    3535               max_version = max(change.comment_history) if change.comment_history else 0;
    36                comment_version = int(cversion or 0) if show_history else max_version;
     36               comment_version = min(int(cversion or 0), max_version) if show_history else max_version;
    3737               show_buttons = not hide_buttons and not show_editor and comment_version == max_version"
    3838      py:strip="">
    3939  <py:def function="commentref(prefix, cnum, cls=None)">
    ${edited_comment if edited_comment is not None else change.comment}</textarea>  
    135135      ${wiki_to_html(context, text, escape_newlines=preserve_newlines)}
    136136    </div>
    137137    <div py:when="show_history" class="comment searchable" xml:space="preserve">
    138       ${wiki_to_html(context, change.comment_history[int(cversion)].comment, escape_newlines=preserve_newlines)}
     138      ${wiki_to_html(context, change.comment_history[comment_version].comment, escape_newlines=preserve_newlines)}
    139139    </div>
    140140    <div py:when="change.comment" class="comment searchable" xml:space="preserve">
    141141      ${wiki_to_html(context, change.comment, escape_newlines=preserve_newlines)}

comment:5 by Ryan J Ollos, 5 years ago

Milestone: 1.21.0.9

comment:6 by Ryan J Ollos, 5 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [14260], merged to trunk in [14261].

comment:7 by Ryan J Ollos, 5 years ago

Release Notes: modified (diff)

comment:8 by Ryan J Ollos, 4 years ago

[14260] and [14261] were refactored in [14451] and [14452].

Modify Ticket

Change Properties
Set your email in Preferences
Action
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.