diff options
10 files changed, 43 insertions, 5 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 06ddd7a4e4..d9c338f15d 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -75,16 +75,23 @@ class AppCache(object): app_module = import_module(app_name) try: imp.find_module('models', app_module.__path__) + except ImportError: + self.nesting_level -= 1 + # App has no models module, that's not a problem. + return None + try: + models = import_module('.models', app_name) except ImportError: self.nesting_level -= 1 if can_postpone: - # Either the app has no models, or the package is still being + # Either the app has an error, or the package is still being # imported by Python and the model module isn't available yet. # We will check again once all the recursion has finished (in # populate). self.postponed.append(app_name) - return None - models = import_module('.models', app_name) + return None + else: + raise self.nesting_level -= 1 if models not in self.app_store: self.app_store[models] = len(self.app_store) diff --git a/tests/regressiontests/admin_scripts/complex_app/__init__.py b/tests/regressiontests/admin_scripts/complex_app/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/__init__.py diff --git a/tests/regressiontests/admin_scripts/complex_app/admin/__init__.py b/tests/regressiontests/admin_scripts/complex_app/admin/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/admin/__init__.py diff --git a/tests/regressiontests/admin_scripts/complex_app/admin/foo.py b/tests/regressiontests/admin_scripts/complex_app/admin/foo.py new file mode 100644 index 0000000000..1b933d028d --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/admin/foo.py @@ -0,0 +1,3 @@ +from django.contrib import admin +from admin_scripts.complex_app.models.foo import Foo +admin.site.register(Foo) diff --git a/tests/regressiontests/admin_scripts/complex_app/models/__init__.py b/tests/regressiontests/admin_scripts/complex_app/models/__init__.py new file mode 100644 index 0000000000..a4d6d9539a --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/models/__init__.py @@ -0,0 +1,4 @@ +from admin_scripts.complex_app.models.bar import Bar +from admin_scripts.complex_app.models.foo import Foo + +__all__ = ['Foo', 'Bar'] diff --git a/tests/regressiontests/admin_scripts/complex_app/models/bar.py b/tests/regressiontests/admin_scripts/complex_app/models/bar.py new file mode 100644 index 0000000000..1da16f8f65 --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/models/bar.py @@ -0,0 +1,7 @@ +from django.db import models + +from ..admin import foo +class Bar(models.Model): + name = models.CharField(max_length=5) + class Meta: + app_label = 'complex_app' diff --git a/tests/regressiontests/admin_scripts/complex_app/models/foo.py b/tests/regressiontests/admin_scripts/complex_app/models/foo.py new file mode 100644 index 0000000000..70c285e392 --- /dev/null +++ b/tests/regressiontests/admin_scripts/complex_app/models/foo.py @@ -0,0 +1,6 @@ +from django.db import models + +class Foo(models.Model): + name = models.CharField(max_length=5) + class Meta: + app_label = 'complex_app' diff --git a/tests/regressiontests/admin_scripts/simple_app/__init__.py b/tests/regressiontests/admin_scripts/simple_app/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/admin_scripts/simple_app/__init__.py diff --git a/tests/regressiontests/admin_scripts/simple_app/models.py b/tests/regressiontests/admin_scripts/simple_app/models.py new file mode 100644 index 0000000000..65b30ed38a --- /dev/null +++ b/tests/regressiontests/admin_scripts/simple_app/models.py @@ -0,0 +1 @@ +from admin_scripts.complex_app.models.bar import Bar diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 62a1b49637..77ed8d25cc 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -957,7 +957,7 @@ class ManageMultipleSettings(AdminScriptTestCase): self.assertOutput(err, "Unknown command: 'noargs_command'") -class ManageValidateImportErrorsReported(AdminScriptTestCase): +class ManageValidate(AdminScriptTestCase): def tearDown(self): self.remove_settings('settings.py') @@ -976,7 +976,17 @@ class ManageValidateImportErrorsReported(AdminScriptTestCase): out, err = self.run_manage(args) self.assertNoOutput(out) self.assertOutput(err, 'ImportError') - + + def test_complex_app(self): + "manage.py validate does not raise an ImportError validating a complex app with nested calls to load_app" + self.write_settings('settings.py', + apps=['admin_scripts.complex_app', 'admin_scripts.simple_app'], + sdict={'DEBUG': True}) + args = ['validate'] + out, err = self.run_manage(args) + self.assertNoOutput(err) + self.assertOutput(out, '0 errors found') + ########################################################################## # COMMAND PROCESSING TESTS |