Edgewall Software
Modify ↓

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#11385 closed defect (fixed)

Genshi cannot handle encoded exception message when a Wiki Macros is failed

Reported by: t2y <tetsuya.morimoto@…> Owned by: t2y <tetsuya.morimoto@…>
Priority: low Milestone: 0.12.6
Component: wiki system Version: 1.0-stable
Severity: normal Keywords:
Cc: Ryan J Ollos, Jun Omae Branch:
Release Notes:

Fix Genshi UnicodeDecodeError error during wiki rendering when dealing an exception with non-ascii bytes

API Changes:
Internal Changes:

Description

I encountered this bug after my Trac was migrated 0.12 to 1.0.2dev_r12278. My Trac has many reports including Wiki Macros, and then a macro is failed for some reason like this. Our database is postgresql and it returns the encoded error message including Japanese.

2013-12-01 11:35:59,458 Trac[formatter] ERROR: Macro TicketQuery(version=v4.0,order=time,time=today..,col=id|summary|component|status|version|milestone|priority|time|reporter|qa_contact) failed:
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/wiki/formatter.py", line 766, in _macro_formatter
    return macro.ensure_inline(macro.process(args))
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/wiki/formatter.py", line 357, in process
    text = self.processor(text)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/wiki/formatter.py", line 344, in _macro_processor
    text)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/ticket/query.py", line 1332, in expand_macro
    tickets = query.execute(req)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/ticket/query.py", line 302, in execute
    self.num_items = self._count(sql, args)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/ticket/query.py", line 283, in _count
    % sql, args)[0][0]
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/db/api.py", line 122, in execute
    return db.execute(query, params)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/db/util.py", line 121, in execute
    cursor.execute(query, params)
  File "/usr/local/lib/python2.6/dist-packages/Trac-1.0.2dev_r12278-py2.6.egg/trac/db/util.py", line 65, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
ProgrammingError: 列参照"status"は曖昧です
LINE 1: SELECT COUNT(*) FROM (SELECT t.status AS status,t.summary AS...

Currently, Genshi expects the unicode string, but _macro_formatter() function doesn't consider the string type when an exception happened.

  • trac/wiki/formatter.py
     757     def _macro_formatter(self, match, fullmatch, macro, only_inline=False):      
     758         name = fullmatch.group('macroname')                                      
     759         if name.lower() == 'br':                                                 
     760             return '<br />'                                                      
     761         if name and name[-1] == '?': # Macro?() shortcut for MacroList(Macro)    
     762             args = name[:-1] or '*'                                              
     763         else:                                                                    
     764             args = fullmatch.group('macroargs')                                  
     765         try:                                                                     
     766             return macro.ensure_inline(macro.process(args))                      
     767         except Exception, e:                                                     
     768             self.env.log.error('Macro %s(%s) failed: %s' %                       
     769                     (name, args, exception_to_unicode(e, traceback=True)))       
     770             return system_message('Error: Macro %s(%s) failed' % (name, args),   
     771                                   e)
    

Attachments (1)

fix-exception_to_unicode.patch​ (538 bytes ) - added by t2y <tetsuya.morimoto@…> 13 years ago.
patch to decode the exception

Download all attachments as: .zip

Change History (13)

by t2y <tetsuya.morimoto@…>, 13 years ago

patch to decode the exception

comment:1 by t2y <tetsuya.morimoto@…>, 13 years ago

Applying attached patch works (handles the error appropriately) for my Trac.

comment:2 by Jun Omae, 13 years ago

The ProgrammingError is caused by changes in #11140. I reopened it, now.

in reply to:  2 comment:3 by t2y <tetsuya.morimoto@…>, 13 years ago

Replying to jomae:

The ProgrammingError is caused by changes in #11140. I reopened it, now.

The TicketQuery Macro could show correctly by adding format=table.

comment:4 by Jun Omae, 13 years ago

Milestone: 1.0.2 → 0.12.6
Owner: set to Jun Omae
Status: new → assigned

Thanks. The issue leads TracError with Genshi UnicodeDecodeError error in the user's browser.

2013-12-05 17:13:55,168 Trac[main] WARNING: [192.168.11.17] HTTPInternalError: 500 Trac Error (Genshi UnicodeDecodeError error while rendering template (unknown template location))

The patch looks good and would make wiki rendering robust. Also we should apply to 0.12-stable. I'll push it and unit tests.

comment:5 by Jun Omae, 13 years ago

Proposed changes can be found in log:jomae.git:ticket11385_0.12.6dev for 0.12-stable and log:jomae.git:ticket11385 for 1.0-stable.

comment:6 by Ryan J Ollos, 13 years ago

I tested the 1.0-stable branch and it works well.

One trivial thing is to reorder the imports Component, implements, TracError → Component, TracError, implements, as the latter seems to be our normal convention in the codebase.

comment:7 by Ryan J Ollos, 13 years ago

Cc: Ryan J Ollos added

comment:8 by Jun Omae, 13 years ago

Sure. Thanks for your testing and reviewing!

comment:9 by Jun Omae, 13 years ago

Release Notes: modified (diff)
Resolution: → fixed
Status: assigned → closed

Fixed in [12295] and merged in [12296,12297].

comment:10 by Jun Omae, 13 years ago

Owner: changed from Jun Omae to t2y <tetsuya.morimoto@…>

comment:11 by t2y <tetsuya.morimoto@…>, 13 years ago

After applying r12296 to my Trac, I confirmed this bug was fixed. Thank you jomae!

comment:12 by Jun Omae, 13 years ago

Cc: Jun Omae added

Thanks for the feedback. The ProgrammingError, root cause of the issue, has been fixed in [12299].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain t2y <tetsuya.morimoto@…>.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from t2y <tetsuya.morimoto@…> 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.