Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21443 closed Bug (fixed)

On PY3 if error on import, cannot show debug info

Reported by: Bouke Haarsma Owned by: Bouke Haarsma
Component: Python 3 Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Traceback (most recent call last):
  File "/django/core/urlresolvers.py", line 339, in urlconf_module
    return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/django/core/handlers/base.py", line 101, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/django/core/urlresolvers.py", line 318, in resolve
    for pattern in self.url_patterns:
  File "/django/core/urlresolvers.py", line 346, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/django/core/urlresolvers.py", line 341, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File ".virtualenv/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1024, in load_module
  File "<frozen importlib._bootstrap>", line 1005, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 870, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  ...
ImportError: cannot import name urlencode

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/django/core/handlers/wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "/django/core/handlers/base.py", line 196, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/django/core/handlers/base.py", line 231, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/django/views/debug.py", line 69, in technical_500_response
    html = reporter.get_traceback_html()
  File "/django/views/debug.py", line 323, in get_traceback_html
    c = Context(self.get_traceback_data())
  File "/django/views/debug.py", line 281, in get_traceback_data
    frames = self.get_traceback_frames()
  File "/django/views/debug.py", line 428, in get_traceback_frames
    pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
  File "/django/views/debug.py", line 379, in _get_lines_from_file
    source = loader.get_source(module_name)
  File "<frozen importlib._bootstrap>", line 607, in _requires_frozen_wrapper
ImportError: importlib._bootstrap is not a frozen module

There is an error in my views somewhere, which are being imported as part of my urls.py. The import of the urls fails, and should display an error message. However this cryptic message is shown in the terminal and I have to sift through non-relevant stack traces to get to the real problem.

Change History (10)

comment:1 Changed 3 years ago by Bouke Haarsma

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

When I change line 379 to the below, I get a normal debug view with stack trace.

            try:
                source = loader.get_source(module_name)
            except ImportError:
                source = None

comment:2 Changed 3 years ago by Tim Graham

Component: UncategorizedPython 3
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 Changed 3 years ago by Bouke Haarsma

Has patch: set

PR: https://github.com/django/django/pull/1948

The fix should probably also be backported to 1.6, as it will bite every user running Django on PY3 while working on a project's code.

comment:4 Changed 3 years ago by Claude Paroz

I cannot reproduce on Python 3.2, I suppose this is specific to Python 3.3?

comment:5 Changed 3 years ago by Bouke Haarsma

Cccording to tox it seems to manifest on Python 3.3 only:

ERROR:   py33-sqlite: commands failed
  py32-sqlite: commands succeeded
  py27-sqlite: commands succeeded

Python 3.3 (like 3.2) is installed on OS X using Homebrew.

comment:6 Changed 3 years ago by productions@…

Owner: changed from nobody to anonymous
Status: newassigned

I've also just run into this issue. I'm running Django 1.6, with Python 3.3, Apache 2.4.6 with mod_wsgi, on Ubuntu Server 13.04.

comment:7 Changed 3 years ago by Bouke Haarsma

Owner: changed from anonymous to Bouke Haarsma

comment:8 in reply to:  6 Changed 3 years ago by productions@…

Replying to productions@…:

I've also just run into this issue. I'm running Django 1.6, with Python 3.3, Apache 2.4.6 with mod_wsgi, on Ubuntu Server 13.04.

I can confirm the above patch provided by bourke does solve the issue on my implementation.

comment:9 Changed 3 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In 18185724e614fb3449612ce3df811af32fbc0582:

Fixed #21443 -- Cannot show debug info on PY3's importlib

Thanks productions@… for the review.

comment:10 Changed 3 years ago by Claude Paroz <claude@…>

In d55df0b81083d8aa02145ac5885a855a9c9577b3:

[1.6.x] Fixed #21443 -- Cannot show debug info on PY3's importlib

Thanks productions@… for the review.
Backport of 18185724e6 from master.

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