Browse Source

Django support now requires 1.8+

Ask Solem 8 years ago
parent
commit
9444449aec
2 changed files with 8 additions and 27 deletions
  1. 5 19
      celery/fixups/django.py
  2. 3 8
      t/unit/fixups/test_django.py

+ 5 - 19
celery/fixups/django.py

@@ -106,13 +106,9 @@ class DjangoWorkerFixup(object):
         self._cache = import_module('django.core.cache')
         self._settings = symbol_by_name('django.conf:settings')
 
-        try:
-            self.interface_errors = (
-                symbol_by_name('django.db.utils.InterfaceError'),
-            )
-        except (ImportError, AttributeError):
-            self._interface_errors = ()
-
+        self.interface_errors = (
+            symbol_by_name('django.db.utils.InterfaceError'),
+        )
         self.DatabaseError = symbol_by_name('django.db:DatabaseError')
 
     def django_setup(self):
@@ -120,19 +116,9 @@ class DjangoWorkerFixup(object):
         django.setup()
 
     def validate_models(self):
+        from django.core.checks import run_checks
         self.django_setup()
-        try:
-            from django.core.checks import run_checks
-        except ImportError:  # django < 1.7
-            from django.core.management.validation import get_validation_errors
-            s = StringIO()
-            num_errors = get_validation_errors(s, None)
-            if num_errors:
-                raise RuntimeError(
-                    'One or more Django models did not validate:\n{0}'.format(
-                        s.getvalue()))
-        else:
-            run_checks()
+        run_checks()
 
     def install(self):
         signals.beat_embedded_init.connect(self.close_database)

+ 3 - 8
t/unit/fixups/test_django.py

@@ -242,18 +242,13 @@ class test_DjangoWorkerFixup(FixupCase):
                 f.on_worker_ready()
 
     def test_validate_models(self, patching):
-        patching('celery.fixups.django.symbol_by_name')
-        patching('celery.fixups.django.import_module')
         f = self.Fixup(self.app)
-        patching.modules('django.core.management.validation')
         f.django_setup = Mock(name='django.setup')
-        from django.core.management.validation import get_validation_errors
-        get_validation_errors.return_value = 0
+        patching.modules('django.core.checks')
+        from django.core.checks import run_checks
         f.validate_models()
         f.django_setup.assert_called_with()
-        get_validation_errors.return_value = 3
-        with pytest.raises(RuntimeError):
-            f.validate_models()
+        run_checks.assert_called_with()
 
     def test_django_setup(self, patching):
         patching('celery.fixups.django.symbol_by_name')