Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Karen Tracey authored April 12, 2010
5  django/db/models/loading.py
@@ -5,6 +5,7 @@
5 5
 from django.utils.datastructures import SortedDict
6 6
 from django.utils.importlib import import_module
7 7
 
  8
+import imp
8 9
 import sys
9 10
 import os
10 11
 import threading
@@ -71,8 +72,9 @@ def load_app(self, app_name, can_postpone=False):
71 72
         """
72 73
         self.handled[app_name] = None
73 74
         self.nesting_level += 1
  75
+        app_module = import_module(app_name)
74 76
         try:
75  
-            models = import_module('.models', app_name)
  77
+            imp.find_module('models', app_module.__path__)
76 78
         except ImportError:
77 79
             self.nesting_level -= 1
78 80
             if can_postpone:
@@ -82,6 +84,7 @@ def load_app(self, app_name, can_postpone=False):
82 84
                 # populate).
83 85
                 self.postponed.append(app_name)
84 86
             return None
  87
+        models = import_module('.models', app_name)
85 88
         self.nesting_level -= 1
86 89
         if models not in self.app_store:
87 90
             self.app_store[models] = len(self.app_store)
0  tests/regressiontests/admin_scripts/broken_app/__init__.py
No changes.
1  tests/regressiontests/admin_scripts/broken_app/models.py
... ...
@@ -0,0 +1 @@
  1
+from django.db import modelz
28  tests/regressiontests/admin_scripts/tests.py
@@ -13,7 +13,7 @@
13 13
 from django.conf import settings
14 14
 
15 15
 class AdminScriptTestCase(unittest.TestCase):
16  
-    def write_settings(self, filename, apps=None, is_dir=False):
  16
+    def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
17 17
         test_dir = os.path.dirname(os.path.dirname(__file__))
18 18
         if is_dir:
19 19
             settings_dir = os.path.join(test_dir,filename)
@@ -39,6 +39,10 @@ def write_settings(self, filename, apps=None, is_dir=False):
39 39
         if apps:
40 40
             settings_file.write("INSTALLED_APPS = %s\n" % apps)
41 41
 
  42
+        if sdict:
  43
+            for k, v in sdict.items():
  44
+                settings_file.write("%s = %s\n" % (k, v))
  45
+
42 46
         settings_file.close()
43 47
 
44 48
     def remove_settings(self, filename, is_dir=False):
@@ -952,6 +956,28 @@ def test_custom_command_with_environment(self):
952 956
         self.assertNoOutput(out)
953 957
         self.assertOutput(err, "Unknown command: 'noargs_command'")
954 958
 
  959
+
  960
+class ManageValidateImportErrorsReported(AdminScriptTestCase):
  961
+    def tearDown(self):
  962
+        self.remove_settings('settings.py')
  963
+
  964
+    def test_nonexistent_app(self):
  965
+        "manage.py validate reports an error on a non-existent app in INSTALLED_APPS"
  966
+        self.write_settings('settings.py', apps=['admin_scriptz.broken_app'], sdict={'USE_I18N': False})
  967
+        args = ['validate']
  968
+        out, err = self.run_manage(args)
  969
+        self.assertNoOutput(out)
  970
+        self.assertOutput(err, 'No module named admin_scriptz.broken_app')
  971
+
  972
+    def test_broken_app(self):
  973
+        "manage.py validate reports an ImportError if an app's models.py raises one on import"
  974
+        self.write_settings('settings.py', apps=['admin_scripts.broken_app'])
  975
+        args = ['validate']
  976
+        out, err = self.run_manage(args)
  977
+        self.assertNoOutput(out)
  978
+        self.assertOutput(err, 'ImportError')
  979
+       
  980
+
955 981
 ##########################################################################
956 982
 # COMMAND PROCESSING TESTS
957 983
 # Check that user-space commands are correctly handled - in particular,

0 notes on commit 55c31fb

Please sign in to comment.
Something went wrong with that request. Please try again.