Opened 8 years ago

Closed 8 years ago

#4700 closed (fixed)

urlresolvers.get_callable fails in case of running tests

Reported by: anonymous Owned by: adrian
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by mtredinnick)

urlresolvers.get_callable is raising an exception in " test" mode for any {% url %} tag:

    self.reverse_dict[pattern.callback] = (pattern,)
  File "/Users/phausel/site-packages/django/core/", line 152, in _get_callback
    self._callback = get_callable(self._callback_str)
  File "/Users/phausel/site-packages/django/utils/", line 16, in wrapper
    result = func(*args)
  File "/Users/phausel/site-packages/django/core/", line 29, in get_callable
    lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
  File "/Users/phausel/site-packages/django/contrib/admin/views/", 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 Changed 8 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

sorry, I forgot to mention: get_callable is a brand new feature, it was introduced just on 06/23/07 (to resolve #4566)

comment:2 Changed 8 years ago by anonymous

the error goes away if django.contrib.admin is not included in

comment:3 Changed 8 years ago by mtredinnick

  • Description modified (diff)

Unbroke description.

comment:4 Changed 8 years ago by mtredinnick

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 to work out what what _callback_str is at that point.

comment:5 Changed 8 years ago by anonymous

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
callable: django.contrib.admin.views.doc.model_detail

'str' object is not callable

callable: django.contrib.admin.views.doc.model_index
'str' object is not callable

callable: django.contrib.admin.views.doc.view_detail

'str' object is not callable

callable: django.contrib.admin.views.doc.view_index
'str' object is not callable

callable: django.contrib.admin.views.doc.template_filter_index
'str' object is not callable

callable: django.contrib.admin.views.doc.template_tag_index
'str' object is not callable

callable: django.contrib.admin.views.doc.bookmarklets
'str' object is not callable

callable: django.contrib.admin.views.doc.doc_index
'str' object is not callable

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 Changed 8 years ago by anonymous

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.

comment:7 follow-up: Changed 8 years ago by anonymous

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 to make sure _ got reassigned every single time

comment:8 in reply to: ↑ 7 Changed 8 years ago by anonymous

hey anonymous, add "from django.utils.translation import gettext_lazy as _" to instead

comment:9 Changed 8 years ago by james

yes, adding "from django.utils.translation import gettext_lazy as _" to solves the issue

comment:10 Changed 8 years ago by mtredinnick

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

This was fixed as part of [5609].

Note: See TracTickets for help on using tickets.
Back to Top