Skip to content

Commit afe17fb

Browse files
committed
Cannot do like #226
A unittest reminded me why it doesn't catch ImportError, it's because if there is a syntax error in the tasks.py module the exception would be silenced, which makes it very hard to debug.
1 parent 73985ea commit afe17fb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

djcelery/loaders.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44
import imp
55
import importlib
6-
import warnings
76

87
from datetime import datetime
8+
from warnings import warn
99

1010
from celery import signals
1111
from celery.datastructures import DictAttribute
@@ -64,7 +64,7 @@ def read_configuration(self):
6464
settings.CELERY_RESULT_BACKEND = 'database'
6565
if NO_TZ:
6666
if getattr(settings, 'CELERY_ENABLE_UTC', None):
67-
warnings.warn('CELERY_ENABLE_UTC requires Django 1.4+')
67+
warn('CELERY_ENABLE_UTC requires Django 1.4+')
6868
settings.CELERY_ENABLE_UTC = False
6969
return DictAttribute(settings)
7070

@@ -130,8 +130,8 @@ def on_worker_init(self):
130130

131131
def warn_if_debug(self, **kwargs):
132132
if settings.DEBUG:
133-
warnings.warn('Using settings.DEBUG leads to a memory leak, never '
134-
'use this setting in production environments!')
133+
warn('Using settings.DEBUG leads to a memory leak, never '
134+
'use this setting in production environments!')
135135

136136
def import_default_modules(self):
137137
super(DjangoLoader, self).import_default_modules()
@@ -184,7 +184,12 @@ def find_related_module(app, related_name):
184184

185185
try:
186186
app_path = importlib.import_module(app).__path__
187-
except (AttributeError, ImportError):
187+
except ImportError as exc:
188+
warn('Autodiscover: Error importing %s.%s: %r' % (
189+
app, related_name, exc,
190+
))
191+
return
192+
except AttributeError:
188193
return
189194

190195
try:

0 commit comments

Comments
 (0)