Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13335: Adjusted the r12950 fix to properly handle import error…

…s resulting from nested calls to load_app.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12972 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 48dd5f13a351048d40803cbb95e60ed775d980cd 1 parent d8910e9
Karen Tracey authored April 14, 2010
13  django/db/models/loading.py
@@ -75,16 +75,23 @@ def load_app(self, app_name, can_postpone=False):
75 75
         app_module = import_module(app_name)
76 76
         try:
77 77
             imp.find_module('models', app_module.__path__)
  78
+        except ImportError: 
  79
+            self.nesting_level -= 1
  80
+            # App has no models module, that's not a problem.
  81
+            return None
  82
+        try:
  83
+            models = import_module('.models', app_name)
78 84
         except ImportError:
79 85
             self.nesting_level -= 1
80 86
             if can_postpone:
81  
-                # Either the app has no models, or the package is still being
  87
+                # Either the app has an error, or the package is still being
82 88
                 # imported by Python and the model module isn't available yet.
83 89
                 # We will check again once all the recursion has finished (in
84 90
                 # populate).
85 91
                 self.postponed.append(app_name)
86  
-            return None
87  
-        models = import_module('.models', app_name)
  92
+                return None
  93
+            else:
  94
+                raise
88 95
         self.nesting_level -= 1
89 96
         if models not in self.app_store:
90 97
             self.app_store[models] = len(self.app_store)
0  tests/regressiontests/admin_scripts/complex_app/__init__.py
No changes.
0  tests/regressiontests/admin_scripts/complex_app/admin/__init__.py
No changes.
3  tests/regressiontests/admin_scripts/complex_app/admin/foo.py
... ...
@@ -0,0 +1,3 @@
  1
+from django.contrib import admin
  2
+from admin_scripts.complex_app.models.foo import Foo
  3
+admin.site.register(Foo)
4  tests/regressiontests/admin_scripts/complex_app/models/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+from admin_scripts.complex_app.models.bar import Bar
  2
+from admin_scripts.complex_app.models.foo import Foo
  3
+
  4
+__all__ = ['Foo', 'Bar']
7  tests/regressiontests/admin_scripts/complex_app/models/bar.py
... ...
@@ -0,0 +1,7 @@
  1
+from django.db import models
  2
+
  3
+from ..admin import foo
  4
+class Bar(models.Model):
  5
+    name = models.CharField(max_length=5)
  6
+    class Meta:
  7
+        app_label = 'complex_app'
6  tests/regressiontests/admin_scripts/complex_app/models/foo.py
... ...
@@ -0,0 +1,6 @@
  1
+from django.db import models
  2
+
  3
+class Foo(models.Model):
  4
+    name = models.CharField(max_length=5)
  5
+    class Meta:
  6
+        app_label = 'complex_app'
0  tests/regressiontests/admin_scripts/simple_app/__init__.py
No changes.
1  tests/regressiontests/admin_scripts/simple_app/models.py
... ...
@@ -0,0 +1 @@
  1
+from admin_scripts.complex_app.models.bar import Bar
14  tests/regressiontests/admin_scripts/tests.py
@@ -957,7 +957,7 @@ def test_custom_command_with_environment(self):
957 957
         self.assertOutput(err, "Unknown command: 'noargs_command'")
958 958
 
959 959
 
960  
-class ManageValidateImportErrorsReported(AdminScriptTestCase):
  960
+class ManageValidate(AdminScriptTestCase):
961 961
     def tearDown(self):
962 962
         self.remove_settings('settings.py')
963 963
 
@@ -976,7 +976,17 @@ def test_broken_app(self):
976 976
         out, err = self.run_manage(args)
977 977
         self.assertNoOutput(out)
978 978
         self.assertOutput(err, 'ImportError')
979  
-       
  979
+
  980
+    def test_complex_app(self):
  981
+        "manage.py validate does not raise an ImportError validating a complex app with nested calls to load_app"
  982
+        self.write_settings('settings.py',
  983
+            apps=['admin_scripts.complex_app', 'admin_scripts.simple_app'],
  984
+            sdict={'DEBUG': True})
  985
+        args = ['validate']
  986
+        out, err = self.run_manage(args)
  987
+        self.assertNoOutput(err)
  988
+        self.assertOutput(out, '0 errors found')
  989
+
980 990
 
981 991
 ##########################################################################
982 992
 # COMMAND PROCESSING TESTS

0 notes on commit 48dd5f1

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