Opened 15 years ago

Closed 13 years ago

Last modified 13 years ago

#11667 closed New feature (duplicate)

Full traceback if import error before model validation

Reported by: jedie Owned by: nobody
Component: Core (Management commands) Version: 1.1
Severity: Normal Keywords:
Cc: django@…, riddell@…, klaasvanschelven@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I had an import loop in a app model. If i call the management command "runserver", i get only a one line error message, whitch doesn't help to find the real error.

django.core.management.base.execute should display a read traceback. See patch.

Attachments (4)

django_11667_patch.diff (731 bytes ) - added by jedie 15 years ago.
use traceback.format_exc()
django_11667_load_middleware.diff (1.2 KB ) - added by jedie 15 years ago.
patch for #comment:3
django_11667_manage_test.diff (902 bytes ) - added by Allen Riddell 15 years ago.
patch for #comment:4
remove_try_catch (992 bytes ) - added by Klaas van Schelven 14 years ago.
A patch that drops the try/catch block altogether

Download all attachments as: .zip

Change History (19)

by jedie, 15 years ago

Attachment: django_11667_patch.diff added

use traceback.format_exc()

comment:1 by jedie, 15 years ago

Cc: django@… added
Needs tests: set

comment:2 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:3 by jedie, 15 years ago

django.core.management.base.BaseHandler.load_middleware will also "mask" some import errors. Add a separate patch, if settings.DEBUG is on, raise the original error instead of ImproperlyConfigured, so the user will get a helpfull traceback.

by jedie, 15 years ago

patch for #comment:3

comment:4 by Allen Riddell, 15 years ago

Owner: changed from nobody to Allen Riddell
Status: newassigned

I had a similar issue when running tests. I would do a manage.py test and get an django.core.exceptions.ImproperlyConfigured: App with label <label> could not be found. The real culprit was an import loop. As jedie suggests, displaying the original ImportError would be helpful.

I'll attached a patch for the manage.py test case as django_11667_manage_test.diff.

comment:5 by Allen Riddell, 15 years ago

Cc: riddell@… added

comment:6 by Allen Riddell, 15 years ago

Owner: Allen Riddell removed
Status: assignednew

comment:7 by Allen Riddell, 15 years ago

Owner: set to nobody

by Allen Riddell, 15 years ago

patch for #comment:4

comment:8 by peterlundberg, 14 years ago

I agree that wrapping the exceptions makes debugging import errors very hard and would be Good Thing to improve with Django

I have on occasion replaced

raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))

with just

raise

in template/loaders/app_directories.py line 24 (django 1.2.1) which allows me to see what module/file was trying to do the failing import when running manage.py test

A message like 'cannot import %s from %s line %d' from ImportError would help a lot, but that is more a python issue.

comment:9 by Klaas van Schelven, 14 years ago

Any movement on this?

I can't count the number of times I've dived into the Django code and added a 'raise'. Of course, the proper solution would be simply to drop the associated try/catch block, since all it does is obfuscate things.

This can be rewritten:

206         if self.can_import_settings:
207             try:
208                 from django.utils import translation
209                 translation.activate('en-us')
210             except ImportError, e:
211                 # If settings should be available, but aren't,
212                 # raise the error and quit.
213                 sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
214                 sys.exit(1)

I'll submit a patch in a sec.

by Klaas van Schelven, 14 years ago

Attachment: remove_try_catch added

A patch that drops the try/catch block altogether

comment:10 by Klaas van Schelven, 14 years ago

Cc: klaasvanschelven@… added

comment:11 by Gabriel Hurley, 14 years ago

Component: django-admin.py runserverCore (Management commands)

comment:12 by Julien Phalip, 14 years ago

Severity: Normal
Type: New feature

comment:13 by anonymous, 13 years ago

Easy pickings: unset
UI/UX: unset

Thanks so much!!

comment:14 by Aymeric Augustin, 13 years ago

Resolution: duplicate
Status: newclosed

I'm closing this ticket in favor of #16397 which reports the same problem (as far as I can tell) and has a more recent patch.

comment:15 by Aymeric Augustin, 13 years ago

In [17197]:

Fixed #16397 -- Respected the --traceback flag in BaseCommand. This should make import loops easier to debug. Refs #11667, #17369.

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