Opened 6 years ago

Closed 6 years ago

#18594 closed Cleanup/optimization (wontfix)

Passing kwrgs parameter to url function kills django spouriously

Reported by: jbzdak@… Owned by: nobody
Component: Core (URLs) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Consider following

urlpatterns = patterns('',
    url(r'add$', views.add_event, name =  "add_event"),
    url(r'edit/(P<event_id>\d+)$', views.edit_event, "edit_event"),
    url(r'manage$/(P<event_id>\d+)$', views.manage_event, "manage_event"),
    url(r'(P<event_id>\d+)$', views.see_event, "see_event")

url functions have incorrectly passed name (third argument of url function is kwargs argument), because of this error django fails in completely different part of code:

File "/home/jb/programs/meetmove/django/core/handlers/" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/jb/programs/meetmove/../meetmove/utils/" in index
  19.     return render_to_response("index.html", ctx)
File "/home/jb/programs/meetmove/django/shortcuts/" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/jb/programs/meetmove/django/template/" in render_to_string
  169.         t = get_template(template_name)
File "/home/jb/programs/meetmove/django/template/" in get_template
  145.     template, origin = find_template(template_name)
File "/home/jb/programs/meetmove/django/template/" in find_template
  134.             source, display_name = loader(name, dirs)
File "/home/jb/programs/meetmove/django/template/" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "/home/jb/programs/meetmove/django/template/" in load_template
  48.             template = get_template_from_string(source, origin, template_name)
File "/home/jb/programs/meetmove/django/template/" in get_template_from_string
  156.     return Template(source, origin, name)
File "/home/jb/programs/meetmove/django/template/" in __init__
  125.         self.nodelist = compile_string(template_string, origin)
File "/home/jb/programs/meetmove/django/template/" in compile_string
  153.     return parser.parse()
File "/home/jb/programs/meetmove/django/template/" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/django/template/" in do_extends
  214.     nodelist = parser.parse()
File "/home/jb/programs/meetmove/django/template/" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/django/template/" in do_block
  189.     nodelist = parser.parse(('endblock',))
File "/home/jb/programs/meetmove/django/template/" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/utils/templatetags/" in do_fragment
  20.         flatpage_url = urlresolvers.reverse("admin:flatpages_flatpage_change", args = [])
File "/home/jb/programs/meetmove/django/core/" in reverse
  447.                 app_list = resolver.app_dict[ns]
File "/home/jb/programs/meetmove/django/core/" in app_dict
  290.             self._populate()
File "/home/jb/programs/meetmove/django/core/" in _populate
  258.                             lookups.appendlist(name, (new_matches, p_pattern + pat, dict(defaults, **pattern.default_kwargs)))

I gues that it will fail in whatever part of code trigerrs 'urlresolvers.reverse'.

While Diango should fail when creating url with message like: kwargs argument is of inappropriate format.

Change History (1)

comment:1 Changed 6 years ago by Luke Plant

Resolution: wontfix
Status: newclosed

The problem is that I don't think there is a good way of detecting the 'appropriate' format. kwargs can be any mapping type, not just a dictionary, so a check that did isinstance(kwargs, dict) would be needlessly restrictive.

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