From c03c5ff2f0972d036c66c6fd88fd435b8ee9aa00 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 23 May 2024 23:43:31 -0400 Subject: [PATCH] membershipworks: Use `django.utils.timezone.now` instead of `django.db.models.functions.Now` `Now()` produces incorrect results due to timezone mismatch, see https://code.djangoproject.com/ticket/31638 --- membershipworks/tasks/event_survey_emails.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/membershipworks/tasks/event_survey_emails.py b/membershipworks/tasks/event_survey_emails.py index f13d486..0c561e7 100644 --- a/membershipworks/tasks/event_survey_emails.py +++ b/membershipworks/tasks/event_survey_emails.py @@ -4,7 +4,7 @@ from urllib.parse import quote, urlencode from django.conf import settings from django.core import mail -from django.db.models.functions import Now +from django.utils import timezone from cmsmanage.django_q2_helper import q_task_group from cmsmanage.email import TemplatedMultipartEmail @@ -62,8 +62,14 @@ class EventSurveyEmail(TemplatedMultipartEmail): @q_task_group("Send Event Survey Emails") def send_survey_emails(): with mail.get_connection() as conn: + # not using django.db.models.functions.Now() because of + # timezone mismatch, see + # https://code.djangoproject.com/ticket/31638 for event in EventExt.objects.filter( - occurred=True, should_survey=True, survey_email_sent=False, end__lt=Now() + occurred=True, + should_survey=True, + survey_email_sent=False, + end__lt=timezone.now(), ): logger.info("Sending survey messages for event: %s", event)