Code

#20167 closed Bug (fixed)

import_by_path should show the original traceback on an ImportError

Reported by: grampajoe Owned by: grampajoe
Component: Utilities Version: master
Severity: Normal Keywords: import utils
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When django.utils.module_loading.import_by_path encounters an ImportError, it hides the original traceback:

>>> import_by_path('utils_tests.test_module.bad_module.content')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/grampajoe/Projects/django/django/utils/module_loading.py", line 28, in import_by_path
    error_prefix, module_path, e))
django.core.exceptions.ImproperlyConfigured: Error importing module utils_tests.test_module.bad_module: "No module named a_package_name_that_does_not_exist"

That gives us the original exception message, but the traceback isn't relevant or useful.

I've written a fix using six.reraise at https://github.com/grampajoe/django/tree/import-error-reraise.

Attachments (0)

Change History (2)

comment:1 Changed 13 months ago by grampajoe

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to grampajoe
  • Patch needs improvement unset
  • Status changed from new to assigned

Added a pull request with the fix: https://github.com/django/django/pull/979
Tests passing with SQLite.

comment:2 Changed 13 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 2d0db67813d457dc890a2287d9e98593565d650f:

Fixed #20167 -- Preserve the traceback of ImportErrors in import_by_path.

Thanks @carljm for the review.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.