django.utils.module_loading.import_by_path considered harmful
|Reported by:||aaugustin||Owned by:||berkerpeksag|
|Cc:||berker.peksag@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The purpose of this function is to import whatever its argument points to.
If it fails, it should raise ImportError, signalling that an import failed.
Unfortunately, it catches exceptions, including ImportErrors, and re-raises ImproperlyConfigured. Such exception masking makes it needlessly hard to diagnose circular import problems, because it makes it look like the problem comes from inside Django. It becomes supremely perverse when some code in Django catches ImproperlyConfigured and things go wrong further down the line.
I understand that the original intent was to provide more frienly error messages, but I believe that ImportError is a perfectly fine and suitable exception and that replacing it with a more generic one is a net loss.
(I know I'm attacking an old dogma, but this is an easy step in the long standing "improved error reporting" project.)
Change History (15)
comment:5 Changed 3 years ago by berkerpeksag
- Cc berker.peksag@… added
- Has patch set
- Owner changed from nobody to berkerpeksag
- Status changed from new to assigned
comment:14 Changed 3 years ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from assigned to closed