Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11696: Changed app loading code so that it does not sw…

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

r12950 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12951 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 46b9dd3048b6b3c60f7ed49580d1470f5974e96b 1 parent bf5d71f
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
@@ -70,8 +71,9 @@ def load_app(self, app_name, can_postpone=False):
70 71
         """
71 72
         self.handled[app_name] = None
72 73
         self.nesting_level += 1
  74
+        app_module = import_module(app_name)
73 75
         try:
74  
-            models = import_module('.models', app_name)
  76
+            imp.find_module('models', app_module.__path__)
75 77
         except ImportError:
76 78
             self.nesting_level -= 1
77 79
             if can_postpone:
@@ -81,6 +83,7 @@ def load_app(self, app_name, can_postpone=False):
81 83
                 # populate).
82 84
                 self.postponed.append(app_name)
83 85
             return None
  86
+        models = import_module('.models', app_name)
84 87
         self.nesting_level -= 1
85 88
         if models not in self.app_store:
86 89
             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)
@@ -41,6 +41,10 @@ def write_settings(self, filename, apps=None, is_dir=False):
41 41
         if apps:
42 42
             settings_file.write("INSTALLED_APPS = %s\n" % apps)
43 43
 
  44
+        if sdict:
  45
+            for k, v in sdict.items():
  46
+                settings_file.write("%s = %s\n" % (k, v))
  47
+
44 48
         settings_file.close()
45 49
 
46 50
     def remove_settings(self, filename, is_dir=False):
@@ -953,6 +957,28 @@ def test_custom_command_with_environment(self):
953 957
         self.assertNoOutput(out)
954 958
         self.assertOutput(err, "Unknown command: 'noargs_command'")
955 959
 
  960
+
  961
+class ManageValidateImportErrorsReported(AdminScriptTestCase):
  962
+    def tearDown(self):
  963
+        self.remove_settings('settings.py')
  964
+
  965
+    def test_nonexistent_app(self):
  966
+        "manage.py validate reports an error on a non-existent app in INSTALLED_APPS"
  967
+        self.write_settings('settings.py', apps=['admin_scriptz.broken_app'], sdict={'USE_I18N': False})
  968
+        args = ['validate']
  969
+        out, err = self.run_manage(args)
  970
+        self.assertNoOutput(out)
  971
+        self.assertOutput(err, 'No module named admin_scriptz.broken_app')
  972
+
  973
+    def test_broken_app(self):
  974
+        "manage.py validate reports an ImportError if an app's models.py raises one on import"
  975
+        self.write_settings('settings.py', apps=['admin_scripts.broken_app'])
  976
+        args = ['validate']
  977
+        out, err = self.run_manage(args)
  978
+        self.assertNoOutput(out)
  979
+        self.assertOutput(err, 'ImportError')
  980
+       
  981
+
956 982
 ##########################################################################
957 983
 # COMMAND PROCESSING TESTS
958 984
 # Check that user-space commands are correctly handled - in particular,

0 notes on commit 46b9dd3

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