소스 검색

Django: Raise exception if Django version used is < 1.8

Ask Solem 8 년 전
부모
커밋
0c5d01dded
2개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      celery/fixups/django.py
  2. 2 0
      t/unit/fixups/test_django.py

+ 7 - 1
celery/fixups/django.py

@@ -13,7 +13,7 @@ from importlib import import_module
 
 from celery import _state
 from celery import signals
-from celery.exceptions import FixupWarning
+from celery.exceptions import FixupWarning, ImproperlyConfigured
 
 __all__ = ['DjangoFixup', 'fixup']
 
@@ -31,6 +31,11 @@ def _maybe_close_fd(fh):
         pass
 
 
+def _verify_django_version(django):
+    if django.VERSION < (1, 8):
+        raise ImproperlyConfigured('Celery 4.x requires Django 1.8 or later.')
+
+
 def fixup(app, env='DJANGO_SETTINGS_MODULE'):
     """Install Django fixup if settings module environment is set."""
     SETTINGS_MODULE = os.environ.get(env)
@@ -40,6 +45,7 @@ def fixup(app, env='DJANGO_SETTINGS_MODULE'):
         except ImportError:
             warnings.warn(FixupWarning(ERR_NOT_INSTALLED))
         else:
+            _verify_django_version(django)
             return DjangoFixup(app).install()
 
 

+ 2 - 0
t/unit/fixups/test_django.py

@@ -69,6 +69,8 @@ class test_DjangoFixup(FixupCase):
                     fixup(self.app)
                 Fixup.assert_not_called()
             with mock.module_exists('django'):
+                import django
+                django.VERSION = (1, 10, 1)
                 fixup(self.app)
                 Fixup.assert_called()