Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Closed
wants to merge 1 commit into from

2 participants

Bouke Haarsma Claude Paroz
Claude Paroz
Owner

Committed, thanks!

Claude Paroz claudep closed this November 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 20, 2013
Bouke Haarsma Fixed #21443 -- Cannot show debug info on PY3's importlib a8c26cb
This page is out of date. Refresh to see the latest.
5  django/views/debug.py
@@ -388,7 +388,10 @@ def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, mod
388 388
         """
389 389
         source = None
390 390
         if loader is not None and hasattr(loader, "get_source"):
391  
-            source = loader.get_source(module_name)
  391
+            try:
  392
+                source = loader.get_source(module_name)
  393
+            except ImportError:
  394
+                pass
392 395
             if source is not None:
393 396
                 source = source.splitlines()
394 397
         if source is None:
16  tests/view_tests/tests/test_debug.py
@@ -19,6 +19,7 @@
19 19
 from django.test.utils import (override_settings, setup_test_template_loader,
20 20
     restore_template_loaders)
21 21
 from django.utils.encoding import force_text, force_bytes
  22
+from django.utils import importlib, six
22 23
 from django.views.debug import ExceptionReporter
23 24
 
24 25
 from .. import BrokenException, except_args
@@ -239,6 +240,21 @@ def test_message_only(self):
239 240
         self.assertIn('<h2>Request information</h2>', html)
240 241
         self.assertIn('<p>Request data not supplied</p>', html)
241 242
 
  243
+    @skipIf(six.PY2, 'Bug manifests on PY3 only #21443')
  244
+    def test_unfrozen_importlib(self):
  245
+        """
  246
+        importlib is not a frozen app, but its loader thinks it's frozen which
  247
+        results in an importerror on py3. refs #21443
  248
+        """
  249
+        try:
  250
+            request = self.rf.get('/test_view/')
  251
+            importlib.import_module('abc.def.invalid.name')
  252
+        except Exception:
  253
+            exc_type, exc_value, tb = sys.exc_info()
  254
+        reporter = ExceptionReporter(request, exc_type, exc_value, tb)
  255
+        html = reporter.get_traceback_html()
  256
+        self.assertIn('<h1>ImportError at /test_view/</h1>', html)
  257
+
242 258
 
243 259
 class PlainTextReportTests(TestCase):
244 260
     rf = RequestFactory()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.