mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
Ensure the last_reminder datatetime is tz-aware
I don't fully understand the need for this, but I have seen some
tracebacks on app that complain:
File "/home/humbug/humbug-deployments/2013-07-11-19-28-10/zephyr/lib/actions.py", line 1289, in handle_missedmessage_emails
timestamp - user_profile.last_reminder < waitperiod):
TypeError: can't subtract offset-naive and offset-aware datetimes
Since timestamp in this case comes from timestamp_to_datetime
that explicitly sets the tzinfo, we know it's tz-aware. The only
other possibility is that user_profile.last_reminder is **not**
tz-aware, though I am not sure why that would be the case.
(imported from commit 67e33f4510e91fa9de504f0c610515581312c98b)
This commit is contained in:
@@ -15,6 +15,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.utils.importlib import import_module
|
||||
from django.template import loader
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.utils.timezone import utc, is_naive
|
||||
|
||||
from confirmation.models import Confirmation
|
||||
|
||||
@@ -1284,6 +1285,12 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
|
||||
message__id__in=message_ids,
|
||||
flags=~UserMessage.flags.read)]
|
||||
|
||||
last_reminder = user_profile.last_reminder
|
||||
if last_reminder is not None and is_naive(last_reminder):
|
||||
logging.warning("Loaded a user_profile.last_reminder for user %s that's not tz-aware: %s"
|
||||
% (user_profile.user.email, last_reminder))
|
||||
last_reminder = last_reminder.replace(tzinfo=utc)
|
||||
|
||||
waitperiod = datetime.timedelta(hours=UserProfile.EMAIL_REMINDER_WAITPERIOD)
|
||||
if len(messages) == 0 or (user_profile.last_reminder and \
|
||||
timestamp - user_profile.last_reminder < waitperiod):
|
||||
|
||||
Reference in New Issue
Block a user