Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #11696: Changed app loading code so that it does not swallow im…

…port errors that used to be (prior to r10088) raised.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12950 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 55c31fbdefe3bc3c948599b66781e7a9a1dae2a2 1 parent 82b8b67
@kmtracey kmtracey authored
View
5 django/db/models/loading.py
@@ -5,6 +5,7 @@
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
+import imp
import sys
import os
import threading
@@ -71,8 +72,9 @@ def load_app(self, app_name, can_postpone=False):
"""
self.handled[app_name] = None
self.nesting_level += 1
+ app_module = import_module(app_name)
try:
- models = import_module('.models', app_name)
+ imp.find_module('models', app_module.__path__)
except ImportError:
self.nesting_level -= 1
if can_postpone:
@@ -82,6 +84,7 @@ def load_app(self, app_name, can_postpone=False):
# populate).
self.postponed.append(app_name)
return None
+ models = import_module('.models', app_name)
self.nesting_level -= 1
if models not in self.app_store:
self.app_store[models] = len(self.app_store)
View
0  tests/regressiontests/admin_scripts/broken_app/__init__.py
No changes.
View
1  tests/regressiontests/admin_scripts/broken_app/models.py
@@ -0,0 +1 @@
+from django.db import modelz
View
28 tests/regressiontests/admin_scripts/tests.py
@@ -13,7 +13,7 @@
from django.conf import settings
class AdminScriptTestCase(unittest.TestCase):
- def write_settings(self, filename, apps=None, is_dir=False):
+ def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
test_dir = os.path.dirname(os.path.dirname(__file__))
if is_dir:
settings_dir = os.path.join(test_dir,filename)
@@ -39,6 +39,10 @@ def write_settings(self, filename, apps=None, is_dir=False):
if apps:
settings_file.write("INSTALLED_APPS = %s\n" % apps)
+ if sdict:
+ for k, v in sdict.items():
+ settings_file.write("%s = %s\n" % (k, v))
+
settings_file.close()
def remove_settings(self, filename, is_dir=False):
@@ -952,6 +956,28 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'")
+
+class ManageValidateImportErrorsReported(AdminScriptTestCase):
+ def tearDown(self):
+ self.remove_settings('settings.py')
+
+ def test_nonexistent_app(self):
+ "manage.py validate reports an error on a non-existent app in INSTALLED_APPS"
+ self.write_settings('settings.py', apps=['admin_scriptz.broken_app'], sdict={'USE_I18N': False})
+ args = ['validate']
+ out, err = self.run_manage(args)
+ self.assertNoOutput(out)
+ self.assertOutput(err, 'No module named admin_scriptz.broken_app')
+
+ def test_broken_app(self):
+ "manage.py validate reports an ImportError if an app's models.py raises one on import"
+ self.write_settings('settings.py', apps=['admin_scripts.broken_app'])
+ args = ['validate']
+ out, err = self.run_manage(args)
+ self.assertNoOutput(out)
+ self.assertOutput(err, 'ImportError')
+
+
##########################################################################
# COMMAND PROCESSING TESTS
# Check that user-space commands are correctly handled - in particular,
Please sign in to comment.
Something went wrong with that request. Please try again.