@@ -108,6 +108,15 @@ def __str__(self):
108
108
)
109
109
110
110
111
+ class TZNaiveSchedule (schedules .schedule ):
112
+
113
+ def maybe_make_aware (self , dt ):
114
+ """
115
+ Overriding the base method, to be a no-op and returning the dt as is.
116
+ """
117
+ return dt
118
+
119
+
111
120
@python_2_unicode_compatible
112
121
class IntervalSchedule (models .Model ):
113
122
"""Schedule executing every n seconds."""
@@ -134,10 +143,15 @@ class Meta:
134
143
135
144
@property
136
145
def schedule (self ):
137
- return schedules . schedule (
146
+ _schedule = TZNaiveSchedule (
138
147
timedelta (** {self .period : self .every }),
139
- nowfun = lambda : make_aware (now ())
140
148
)
149
+ if getattr (settings , 'DJANGO_CELERY_BEAT_TZ_AWARE' , True ):
150
+ _schedule = schedules .schedule (
151
+ timedelta (** {self .period : self .every }),
152
+ nowfun = lambda : make_aware (now ())
153
+ )
154
+ return _schedule
141
155
142
156
@classmethod
143
157
def from_schedule (cls , schedule , period = SECONDS ):
@@ -218,7 +232,7 @@ def schedule(self):
218
232
day_of_month = self .day_of_month ,
219
233
month_of_year = self .month_of_year ,
220
234
)
221
- if settings . DJANGO_CELERY_BEAT_TZ_AWARE :
235
+ if getattr ( settings , ' DJANGO_CELERY_BEAT_TZ_AWARE' , True ) :
222
236
crontab = TzAwareCrontab (
223
237
minute = self .minute ,
224
238
hour = self .hour ,
0 commit comments