Modify

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#10972 closed defect (fixed)

Crash if `[theme] theme` is not found with Trac 0.12

Reported by: jun66j5 Owned by: jun66j5
Priority: normal Component: ThemeEnginePlugin
Severity: normal Keywords: python2.4 python2.5
Cc: Trac Release: 0.12

Description

With Python 2.4

Traceback (most recent call last):
  File "/home/jun66j5/venv/trac/0.12.5/lib/python2.4/site-packages/trac/web/api.py", line 458, in send_error
    data, 'text/html')
  File "/home/jun66j5/venv/trac/0.12.5/lib/python2.4/site-packages/trac/web/chrome.py", line 836, in render_template
    template = self.load_template(filename, method=method)
  File "/home/jun66j5/venv/trac/0.12.5/lib/python2.4/site-packages/trac/web/chrome.py", line 796, in load_template
    self.templates = TemplateLoader(
  File "/home/jun66j5/venv/trac/0.12.5/lib/python2.4/site-packages/trac/web/chrome.py", line 511, in get_all_templates_dirs
    dirs.extend(provider.get_templates_dirs() or [])
  File "/home/jun66j5/src/trac/trac-hacks/themeengineplugin/trunk/themeengine/web_ui.py", line 45, in get_templates_dirs
    theme = self.system.theme
  File "/home/jun66j5/src/trac/trac-hacks/themeengineplugin/trunk/themeengine/api.py", line 69, in theme
    raise ThemeNotFound(self.theme_name)
  File "/home/jun66j5/src/trac/trac-hacks/themeengineplugin/trunk/themeengine/api.py", line 26, in __init__
    super(TracError, self).__init__('Unknown theme %s'%self.theme_name)
TypeError: super() argument 1 must be type, not classobj

Because Exception class is old-style class on Python 2.4 and super() only works for new-style classes.
See http://docs.python.org/2/library/functions.html#super

$ python2.4
Python 2.4.3 (#1, Jan  9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help(Exception)
Help on class Exception in module exceptions:

class Exception
 |  Common base class for all exceptions.
 |
 |  Methods defined here:
...

With Python 2.5

2013-03-25 12:05:03,807 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/home/jun66j5/venv/trac/0.12.5-py25/lib/python2.5/site-packages/trac/web/main.py", line 522, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/venv/trac/0.12.5-py25/lib/python2.5/site-packages/trac/web/main.py", line 289, in dispatch
    raise HTTPInternalError(e)
  File "/home/jun66j5/venv/trac/0.12.5-py25/lib/python2.5/site-packages/trac/web/api.py", line 46, in __init__
    self.detail = detail.message
  File "/home/jun66j5/venv/trac/0.12.5-py25/lib/python2.5/site-packages/trac/core.py", line 48, in <lambda>
    message = property(lambda self: self._message,
AttributeError: 'ThemeNotFound' object has no attribute '_message'

Exception class is new-style class, however, ThemeNotFound class doesn't work on Python 2.5 with Trac 0.12.

$ python2.5
Python 2.5.6 (r256:88840, Feb 29 2012, 04:03:24)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help(Exception)
Help on class Exception in module exceptions:

class Exception(BaseException)
 |  Common base class for all non-exit exceptions.
 |
 |  Method resolution order:
 |      Exception
 |      BaseException
 |      __builtin__.object
 |
 |  Methods defined here:
...

The patch is the following.

  • themeengine/api.py

     
    2323 
    2424    def __init__(self, name): 
    2525        self.theme_name = name 
    26         super(TracError, self).__init__('Unknown theme %s'%self.theme_name) 
     26        TracError.__init__(self, 'Unknown theme %s' % name) 
    2727 
    2828class IThemeProvider(Interface): 
    2929    """An interface to provide style information.""" 

Attachments (0)

Change History (11)

comment:1 follow-ups: Changed 17 months ago by rjollos

comment:3:ticket:10800 says that the 2.1.x series implemented in trunk are focused on 1.0 compatibility, however I think it would be good to continue to support 0.12 since that is still the LTS version of Trac.

olemis: Note that jun66j5 has repository-wide commit access, so he has the ability to push the changes directly if you give him approval.

comment:2 Changed 17 months ago by rjollos

  • Keywords python2.4 python2.5 added

comment:3 in reply to: ↑ 1 Changed 17 months ago by jun66j5

Replying to rjollos:

comment:3:ticket:10800 says that the 2.1.x series implemented in trunk are focused on 1.0 compatibility, however I think it would be good to continue to support 0.12 since that is still the LTS version of Trac.

Ok. But the same error occurs on Trac 1.0.1 with Python 2.5 and 2.6.

01:23:23 PM Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/web/main.py", line 256, in dispatch
    raise HTTPInternalError(e)
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/web/api.py", line 133, in __init__
    self.detail = detail.message
  File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/core.py", line 48, in <lambda>
    message = property(lambda self: self._message,
AttributeError: 'ThemeNotFound' object has no attribute '_message'
01:26:44 PM Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/home/jun66j5/venv/trac/1.0.1-py26/lib/python2.6/site-packages/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/jun66j5/venv/trac/1.0.1-py26/lib/python2.6/site-packages/trac/web/main.py", line 256, in dispatch
    raise HTTPInternalError(e)
  File "/home/jun66j5/venv/trac/1.0.1-py26/lib/python2.6/site-packages/trac/web/api.py", line 133, in __init__
    self.detail = detail.message
  File "/home/jun66j5/venv/trac/1.0.1-py26/lib/python2.6/site-packages/trac/core.py", line 48, in <lambda>
    message = property(lambda self: self._message,
AttributeError: 'ThemeNotFound' object has no attribute '_message'

comment:4 Changed 17 months ago by rjollos

Ah, okay. I keep forgetting Trac 1.0.x still supports Python 2.5, and also didn't understand at first that it will be an issue with Python 2.6 as well. I guess the fix needs to be applied then ;)

comment:5 in reply to: ↑ 1 Changed 17 months ago by olemis

  • Owner changed from olemis to anonymous
  • Status changed from new to assigned

Replying to rjollos:

comment:3:ticket:10800 says that the 2.1.x series implemented in trunk are focused on 1.0 compatibility, however I think it would be good to continue to support 0.12 since that is still the LTS version of Trac.

olemis: Note that jun66j5 has repository-wide commit access, so he has the ability to push the changes directly if you give him approval.

thanks jun66j5 and rjollos for keeping me informed . I'll try to make some time tomorrow to fix this one and a few other issues related to ThemeEnginePlugin . If you have some code fixing this issue feel free to commit it , but please let me know so that I can review .

comment:6 Changed 17 months ago by olemis

I have to remember not to reply any messages @ 1:00 am ... ;-$

jun66j5 you may commit your suggestion with close #10972

Thanks !
:)

comment:7 Changed 17 months ago by anonymous

  • Owner changed from anonymous to jun66j5
  • Status changed from assigned to new

comment:8 Changed 17 months ago by jun66j5

  • Resolution set to fixed
  • Status changed from new to closed

(In [12794]) ThemeEnginePlugin: fixed errors while initializing ThemeNotFound exception (fixed #10972)

comment:9 Changed 17 months ago by jun66j5

I just pushed the patch and closed the issue. Thanks ;)

comment:10 follow-up: Changed 17 months ago by rjollos

The incompatibility with Python 2.4 seemed pretty clear after Jun explained it, but at first I couldn't see why this wouldn't have worked on Python 2.5/2.6. However, I now think it is this,

The statement:

super(TracError, self).__init__('Unknown theme %s' % self.theme_name)

should have to be:

super(ThemeNotFound, self).__init__('Unknown theme %s' % self.theme_name)

The first argument should be the name self's class, not its superclass, right? It looks like this issue has been around for quite some time, since [5439].

comment:11 in reply to: ↑ 10 Changed 17 months ago by jun66j5

The first argument should be the name self's class, not its superclass, right?

Yah, you're right. super(ThemeNotFound, self).__init__(...) works well on Python 2.5+.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.