Unnecessary imports lead to ImportError
|Reported by:||Klaas van Schelven||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||no|
for appname in settings.INSTALLED_APPS: app = import_module(appname) apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
As you can see, the only reason apps are imported here is to determine their location so a locale path can be tucked on. However, importing apps comes at a cost. There are cases in which this import leads to a circular reference, leading to the inability of the application to load.
There may be more locations where this particular loop over INSTALLED_APPS leads to problems, though I have not encountered them.
On a somewhat related note, I don't think Django provides us with an easy way to loop over the installed apps. We have models.get_apps, but that doesn't work for modelless apps. This might lead to issues such as the one I reported here:
I'll try to reproduce the negative consequences (the ImportError) in a few moments and post the results here. I also have some kind of patch for this running in production, but I can imagine it's not really core-proof. Evaluation is appreciated.
Change History (32)
comment:5 Changed 6 years ago by
|Component:||Uncategorized → Internationalization|
|Triage Stage:||Unreviewed → Accepted|
comment:18 Changed 5 years ago by
|Status:||new → closed|
comment:20 follow-up: 23 Changed 5 years ago by
|Status:||closed → reopened|
|Version:||1.2 → 1.4|
comment:28 Changed 3 years ago by
|Patch needs improvement:||unset|