소스 검색

Do not apply Django fixups if Django is not installed (but show warning). Related to #1311

Ask Solem 12 년 전
부모
커밋
e71a93c728
2개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      celery/exceptions.py
  2. 9 0
      celery/fixups/django.py

+ 4 - 0
celery/exceptions.py

@@ -124,6 +124,10 @@ class CDeprecationWarning(DeprecationWarning):
     pass
 
 
+class FixupWarning(UserWarning):
+    pass
+
+
 class IncompleteStream(Exception):
     """Found the end of a stream of data, but the data is not yet complete."""
 

+ 9 - 0
celery/fixups/django.py

@@ -7,8 +7,13 @@ import warnings
 from datetime import datetime
 
 from celery import signals
+from celery.exceptions import FixupWarning
 
 SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE')
+ERR_NOT_INSTALLED = """\
+Environment variable DJANGO_SETTINGS_MODULE is defined
+but Django is not installed.  Will not apply Django fixups!
+"""
 
 
 def _maybe_close_fd(fh):
@@ -21,6 +26,10 @@ def _maybe_close_fd(fh):
 
 def fixup(app):
     if SETTINGS_MODULE:
+        try:
+            import django
+        except ImportError:
+            warnings.warn(FixupWarning(ERR_NOT_INSTALLED))
         return DjangoFixup(app).install()