Opened 18 years ago
Closed 17 years ago
#4700 closed (fixed)
urlresolvers.get_callable fails in case of running tests
Reported by: | anonymous | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
urlresolvers.get_callable is raising an exception in "manage.py test" mode for any {% url %} tag:
self.reverse_dict[pattern.callback] = (pattern,) File "/Users/phausel/site-packages/django/core/urlresolvers.py", line 152, in _get_callback self._callback = get_callable(self._callback_str) File "/Users/phausel/site-packages/django/utils/functional.py", line 16, in wrapper result = func(*args) File "/Users/phausel/site-packages/django/core/urlresolvers.py", line 29, in get_callable lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) File "/Users/phausel/site-packages/django/contrib/admin/views/doc.py", line 291, in <module> 'AutoField' : _('Integer'), TypeError: 'str' object is not callable
(The weird thing is that it occurs only when running the built in test feature.)
I printed out func_name which was template_detail (from django/contrib/admin/views)
Change History (10)
comment:1 by , 18 years ago
comment:4 by , 18 years ago
I cannot work out how to replicate this problem. If you can provide a very simple example showing the problem, that would make things easier.
All the internal Django tests pass (which include testing the "url" tag), so this isn't something that has broken reverse() completely. And I cannot see what it is expecting to be a callable there.
Perhaps you could put a print statement around line 152 of urlresolvers.py to work out what what _callback_str
is at that point.
comment:5 by , 18 years ago
Hello Malcolm,
I believe it's going to be an issue only if admin is included in the url config as well.
anyway these are func_names that are raising the exception in get_callable:
'str' object is not callable
template_detail
callable: django.contrib.admin.views.doc.model_detail
'str' object is not callable
model_detail
callable: django.contrib.admin.views.doc.model_index
'str' object is not callable
model_index
callable: django.contrib.admin.views.doc.view_detail
'str' object is not callable
view_detail
callable: django.contrib.admin.views.doc.view_index
'str' object is not callable
view_index
callable: django.contrib.admin.views.doc.template_filter_index
'str' object is not callable
template_filter_index
callable: django.contrib.admin.views.doc.template_tag_index
'str' object is not callable
template_tag_index
callable: django.contrib.admin.views.doc.bookmarklets
'str' object is not callable
bookmarklets
callable: django.contrib.admin.views.doc.doc_index
'str' object is not callable
doc_index
and these are _callback_str strings from _get_callback:
callable: django.contrib.admin.views.template.template_validator
callable: django.contrib.auth.views.password_change_done
callable: django.contrib.auth.views.password_change
callable: django.contrib.auth.views.logout
callable: django.views.i18n.javascript_catalog
callable: django.views.defaults.shortcut
callable: django.contrib.admin.views.main.index
callable: django.contrib.auth.views.login
callable: django.views.generic.simple.redirect_to
I hope it helps
comment:6 by , 18 years ago
hi malcolm,
i think it's something to do with overwriting _() by gettext, it seems the reference 'disappears' when urlresolver is called from a test and there are modules included using i18n.
follow-up: 8 comment:7 by , 18 years ago
I guess before the urlresolver change those modules were not looked up that's why it did not happen before,
my solution was to add
def _(s): return gettext(s)
to django.utils.translation.trans_real
and then I added "from django.utils.translation.trans_real import _" to doc.py to make sure _ got reassigned every single time
comment:8 by , 18 years ago
hey anonymous, add "from django.utils.translation import gettext_lazy as _" to doc.py instead
comment:9 by , 17 years ago
yes, adding "from django.utils.translation import gettext_lazy as _" to doc.py solves the issue
comment:10 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This was fixed as part of [5609].
sorry, I forgot to mention: get_callable is a brand new feature, it was introduced just on 06/23/07 (to resolve #4566)