Opened 18 years ago

Last modified 18 years ago

#4319 closed

urlresolvers.RegexURLPattern._get_callback doesn't handle ValueError — at Initial Version

Reported by: django@… Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: Keywords: url resolver _get_callback
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems import raises a ValueError if the module name is empty. This can occur in _get_callback and isn't handled properly:

Using a named URL pattern "blog-post" in a permalink-decorated get_absolute_url method causes the exception detailed below.

Switching the name to "blog.post" instead fools the reverse functions into allowing it because _get_callback receives a non-empty module name.

Traceback (most recent call last):
File "d:\python25\Lib\site-packages\django\template\init.py" in render_node

  1. result = node.render(context)

File "d:\python25\Lib\site-packages\django\template\defaulttags.py" in render

  1. nodelist.append(node.render(context))

File "d:\python25\Lib\site-packages\django\template\init.py" in render

  1. output = self.filter_expression.resolve(context)

File "d:\python25\Lib\site-packages\django\template\init.py" in resolve

  1. obj = resolve_variable(self.var, context)

File "d:\python25\Lib\site-packages\django\template\init.py" in resolve_variable

  1. current = current()

File "d:\python25\Lib\site-packages\django\utils\functional.py" in _curried

  1. return _curried_func(*(args+moreargs), dict(kwargs, morekwargs))

File "d:\python25\Lib\site-packages\django\db\models\base.py" in get_absolute_url

  1. return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self)

File "d:\python25\Lib\site-packages\django\db\models\init.py" in inner

  1. return reverse(bits[0], None, *bits[1:3])

File "d:\python25\Lib\site-packages\django\core\urlresolvers.py" in reverse

  1. return '/' + resolver.reverse(viewname, *args, kwargs)

File "d:\python25\Lib\site-packages\django\core\urlresolvers.py" in reverse

  1. return pattern.reverse_helper(lookup_view, *args, kwargs)

File "d:\python25\Lib\site-packages\django\core\urlresolvers.py" in reverse_helper

  1. sub_match = self.reverse(lookup_view, *args, kwargs)

File "d:\python25\Lib\site-packages\django\core\urlresolvers.py" in reverse

  1. elif pattern.callback == lookup_view or pattern.name == lookup_view:

File "d:\python25\Lib\site-packages\django\core\urlresolvers.py" in _get_callback

  1. self._callback = getattr(import(mod_name, {}, {}, []), func_name)

ValueError at /blog/articles/
Empty module name

Change History (0)

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