Edgewall Software
Modify

Opened 9 years ago

Closed 9 years ago

#12285 closed defect (fixed)

AttributeError: 'TracError' object has no attribute 'replace'

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

Fixed AttributeError when an exception passed to add_notice or add_warning contained text that needed to be escaped (e.g. &&). The error was only seen when Genshi was installed without speedups.

API Changes:
Internal Changes:

Description

[pid 23749 140573412329216] 2015-12-17 10:06:48,386 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/timeline?from=2008-12-03T10:14:17+01:00&precision=second'">, referrer None
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 594, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 251, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/timeline/web_ui.py", line 118, in process_request
    add_warning(req, e)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/chrome.py", line 198, in add_warning
    msg = escape(msg, False)
  File "/usr/local/virtualenv/src/trac-1.1dev/.eggs/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/core.py", line 519, in escape
    text = text.replace('&', '&amp;') \
AttributeError: 'TracError' object has no attribute 'replace'
[pid 10365 140573412329216] 2015-12-17 11:31:40,131 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/timeline?from=2011-02-02T11:38:50+01:00&precision=second'">, referrer 'http://trac.edgewall.org/wiki/TranslationRu'
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 594, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/main.py", line 251, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/timeline/web_ui.py", line 118, in process_request
    add_warning(req, e)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/web/chrome.py", line 198, in add_warning
    msg = escape(msg, False)
  File "/usr/local/virtualenv/src/trac-1.1dev/.eggs/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/core.py", line 519, in escape
    text = text.replace('&', '&amp;') \
AttributeError: 'TracError' object has no attribute 'replace'

Attachments (0)

Change History (6)

comment:1 by Ryan J Ollos, 9 years ago

Related to #12007. Issue is only seen for Genshi without speedups. Is the following patch the best solution?:

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index 696893d..f084c04 100644
    a b def add_warning(req, msg, *args):  
    195195    """
    196196    if args:
    197197        msg %= args
    198     msg = escape(msg, False)
     198    msg = escape(to_unicode(msg), False)
    199199    if msg not in req.chrome['warnings']:
    200200        req.chrome['warnings'].append(msg)
    201201
    def add_notice(req, msg, *args):  
    209209    """
    210210    if args:
    211211        msg %= args
    212     msg = escape(msg, False)
     212    msg = escape(to_unicode(msg), False)
    213213    if msg not in req.chrome['notices']:
    214214        req.chrome['notices'].append(msg)
Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:2 by Ryan J Ollos, 9 years ago

Release Notes: modified (diff)

comment:3 by Jun Omae, 9 years ago

1 failure without Babel.

  Package        Version                                            
  ------------------------------------------------------------------
  Python       : 2.7.3 (default, Dec 18 2014, 19:10:20) 
  [GCC 4.6.3]
  Setuptools   : 0.6                                                
  Genshi       : 0.7                                                
  Babel        : not installed                                      
  sqlite3      : 2.6.0                                              
  PySqlite     : 2.6.3                                              
  MySQLdb      : 1.2.5                                              
  Psycopg2     : 2.6 (dt dec pq3 ext)                               
  SVN bindings : not installed                                      
  Mercurial    : 3.4                                                
  Pygments     : not installed                                      
  Textile      : not installed                                      
  Pytz         : not installed                                      
  ConfigObj    : not installed                                      
  Docutils     : not installed                                      
  Twill        : 0.9                                                
  LXML         : 3.4.4                                              
  coverage     : 4.0a5                                              
  figleaf      : not installed                                      

Variables:
  PATH=/home/jun66j5/venv/py27-1.0/bin::$PATH
  PYTHONPATH=.::$PYTHONPATH
  TRAC_TEST_DB_URI=
  server-options= -p 8000  -r -e 

External dependencies:
  Git version: git version 1.7.9.5

python setup.py egg_info
running egg_info
writing requirements to Trac.egg-info/requires.txt
writing Trac.egg-info/PKG-INFO
writing top-level names to Trac.egg-info/top_level.txt
writing dependency_links to Trac.egg-info/dependency_links.txt
writing entry points to Trac.egg-info/entry_points.txt
reading manifest file 'Trac.egg-info/SOURCES.txt'
writing manifest file 'Trac.egg-info/SOURCES.txt'
python ./trac/test.py --skip-functional-tests 
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
======================================================================
FAIL: test_invalid_date_format_add_warning (trac.timeline.tests.web_ui.TimelineModuleTestCase)
Warning is added when date format is invalid.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/run/shm/7a6e2fd898f45ef48e6606f787200f89be1e54b8/py27-sqlite/trac/timeline/tests/web_ui.py", line 131, in test_invalid_date_format_add_warning
    u'instead.', req.chrome['warnings'])
AssertionError: u'"2011-02-02T11:38:50+01:00&amp;precision=second" is an invalid date, or the date format is not known. Try "MMM d, y" or "YYYY-MM-DDThh:mm:ss\xb1hh:mm" instead.' not found in [<Markup u'"2011-02-02T11:38:50+01:00&amp;precision=second" is an invalid date, or the date format is not known. Try "MM/dd/YY" or "YYYY-MM-DDThh:mm:ss\xb1hh:mm" instead.'>]

----------------------------------------------------------------------
Ran 1523 tests in 20.594s

FAILED (failures=1)

comment:4 by Ryan J Ollos, 9 years ago

Thanks, fixed in [406a4bee/rjollos.git] and test case improved in [54e2b44b/rjollos.git].

I noticed an unrelated issue. It doesn't make sense to mix date and datetime formats in the message Try "MMM d, y" or "YYYY-MM-DDThh:mm:ss±hh:mm" instead. I attempted to address that in [4a28370b/rjollos.git]. A unit test is still needed.

in reply to:  4 comment:5 by Ryan J Ollos, 9 years ago

Replying to rjollos:

I noticed an unrelated issue. It doesn't make sense to mix date and datetime formats in the message Try "MMM d, y" or "YYYY-MM-DDThh:mm:ss±hh:mm" instead. I attempted to address that in [4a28370b/rjollos.git]. A unit test is still needed.

#12295.

comment:6 by Ryan J Ollos, 9 years ago

Resolution: fixed
Status: assignedclosed

Committed with minor changes in [14401], merged to trunk in [14402].

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.