Opened 17 years ago
Closed 17 years ago
#5646 closed defect (fixed)
Missing import of trac.util.translation._
Reported by: | 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 , 17 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
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 , 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
77 77 return True 78 78 79 79 def process_request(self, req): 80 global _ 80 81 panels, providers = self._get_panels(req) 81 82 if not panels: 82 83 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 , 17 years ago
Milestone: | → 0.11 |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
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.
Make sure you're using at least r5773, see: