Opened 10 years ago

Closed 10 years ago

#23495 closed Cleanup/optimization (fixed)

ImportError silenced

Reported by: papaloizouc Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords: exceptions, import, conf, settings
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi sometimes i get import errors silenced by django/conf/__init__.py source code link https://github.com/django/django/blob/885ff6845e54511022677c1f28b84ddd4f2165dd/django/conf/__init__.py#L94

I comment out the except ImportError as e: in order to get a proper stacktrace on where my code crashed.

So for example models.py imports from util.py that actually does not exist i get error ImportError: Could not import settings 'sharehoods.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named util. Because this is not clear what happened in the source code, i uncomment the exception catch in the source code and then i get the real stacktrace where the import error happened in my code so i know how to fix it. I'm not sure why the exception is silenced and re-raised but i personally always have it commented out on my pc so i thought i should mention.

Change History (6)

comment:1 by Aymeric Augustin, 10 years ago

Component: UncategorizedCore (Other)
Easy pickings: unset
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Good intentions that do more harm than good. This happens often in Django!

How could be preserve the tip without destroying the stack trace? Just print it and then raise?

comment:2 by Carl Meyer, 10 years ago

If we just print and then raise, the printed tip would likely be driven right off the screen by the stacktrace and never seen.

Frankly I don't see that particular tip as providing much value over the original ImportError itself.

comment:3 by Aymeric Augustin, 10 years ago

This seems to date back to r105 (don't miss r106).

The error message was improved a bit in [9a524e3c].

I think Jacob won't mind if we drop the try/except.

comment:4 by Claude Paroz, 10 years ago

Has patch: set
Version: 1.6master

comment:5 by Aymeric Augustin, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In fc2b8ddcc8a0d68dcd333a77314c816469ba96af:

Fixed #23495 -- Stopped swallowing real settings import error

Thanks papaloizouc for the report.

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