Opened 3 years ago

Closed 3 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

Description

Consider following urls.py

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:


Traceback:
File "/home/jb/programs/meetmove/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/jb/programs/meetmove/../meetmove/utils/views.py" in index
  19.     return render_to_response("index.html", ctx)
File "/home/jb/programs/meetmove/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/jb/programs/meetmove/django/template/loader.py" in render_to_string
  169.         t = get_template(template_name)
File "/home/jb/programs/meetmove/django/template/loader.py" in get_template
  145.     template, origin = find_template(template_name)
File "/home/jb/programs/meetmove/django/template/loader.py" in find_template
  134.             source, display_name = loader(name, dirs)
File "/home/jb/programs/meetmove/django/template/loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "/home/jb/programs/meetmove/django/template/loader.py" in load_template
  48.             template = get_template_from_string(source, origin, template_name)
File "/home/jb/programs/meetmove/django/template/loader.py" in get_template_from_string
  156.     return Template(source, origin, name)
File "/home/jb/programs/meetmove/django/template/base.py" in __init__
  125.         self.nodelist = compile_string(template_string, origin)
File "/home/jb/programs/meetmove/django/template/base.py" in compile_string
  153.     return parser.parse()
File "/home/jb/programs/meetmove/django/template/base.py" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/django/template/loader_tags.py" in do_extends
  214.     nodelist = parser.parse()
File "/home/jb/programs/meetmove/django/template/base.py" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/django/template/loader_tags.py" in do_block
  189.     nodelist = parser.parse(('endblock',))
File "/home/jb/programs/meetmove/django/template/base.py" in parse
  267.                     compiled_result = compile_func(self, token)
File "/home/jb/programs/meetmove/utils/templatetags/fragment.py" in do_fragment
  20.         flatpage_url = urlresolvers.reverse("admin:flatpages_flatpage_change", args = [flatpage.id])
File "/home/jb/programs/meetmove/django/core/urlresolvers.py" in reverse
  447.                 app_list = resolver.app_dict[ns]
File "/home/jb/programs/meetmove/django/core/urlresolvers.py" in app_dict
  290.             self._populate()
File "/home/jb/programs/meetmove/django/core/urlresolvers.py" 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 3 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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