Edgewall Software
Modify

Opened 17 years ago

Closed 17 years ago

#5646 closed defect (fixed)

Missing import of trac.util.translation._

Reported by: Dave Abrahams <dave@…> Owned by: Christopher Lenz
Priority: high Milestone: 0.11
Component: admin/web Version: devel
Severity: critical Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

In trac.admin.web_ui.py, line 83, the name _ is used without previously defining it.

raceback (most recent call last):
  File "/usr/local/lib/python2.4/site-packages/Trac-0.11dev_r5790-py2.4.egg/trac/web/main.py", line 436, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/lib/python2.4/site-packages/Trac-0.11dev_r5790-py2.4.egg/trac/web/main.py", line 221, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/lib/python2.4/site-packages/Trac-0.11dev_r5790-py2.4.egg/trac/admin/web_ui.py", line 83, in process_request
    raise HTTPNotFound(_('No administration panels available'))
UnboundLocalError: local variable '_' referenced before assignment

I tried adding the import at the top of the file, but that didn't fix my problem. So then I ended up stomping into every function that uses _ in that way and doing the import there. Whether that's the right fix or overkill is unclear to me. As you can see from http://news.gmane.org/find-root.php?message_id=%3c87sl8laxcx.fsf%40grogan.peloton%3e this thread I don't really understand how these differences in behavior between module-scope and function-scope imports arise.

Attachments (0)

Change History (4)

comment:1 by Christian Boos, 17 years ago

Resolution: worksforme
Status: newclosed

comment:2 by Dave Abrahams <dave@…>, 17 years ago

Resolution: worksforme
Status: closedreopened

I'm using r5790. I think you've missed my point. For some reason, the import at the top of the file as shown at source:/trunk/trac/admin/web_ui.py@5773#L33 doesn't work.

comment:3 by osimons <simon-code@…>, 17 years ago

web_ui.py source code looks fine reading it, but there is something wrong here. I disabled all my panels to make the HTTPNotFound trigger. And it did - same error as in the ticket description. Using r5789.

Here is what solved it for me:

  • trac/admin/web_ui.py

     
    7777            return True
    7878
    7979    def process_request(self, req):
     80        global _
    8081        panels, providers = self._get_panels(req)
    8182        if not panels:
    8283            raise HTTPNotFound(_('No administration panels available'))

Strange… Now, why the global keyword is necessary here is beyond me - I have personally never had use for it before, and not seen it anywhere else in the Trac source I think. There is something in the way this is implemented that provides ambiguity with regards to '_'.

Any trac-devs (or others) able to figure this one out?

comment:4 by Christopher Lenz, 17 years ago

Milestone: 0.11
Resolution: fixed
Status: reopenedclosed

This should be fixed [5805]. The problem was a local variable declaration also using the underscore. We'll have to be more careful about this, and avoid using an underscore for ignored data.

Modify Ticket

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