def deliver_email(email: ScheduledEmail) -> None: data = ujson.loads(email.data) if email.users.exists(): data['to_user_ids'] = [user.id for user in email.users.all()] if email.address is not None: data['to_emails'] = [email.address] handle_send_email_format_changes(data) send_email(**data) email.delete()
def deliver_email(email: ScheduledEmail) -> None: data = orjson.loads(email.data) user_ids = list(email.users.values_list("id", flat=True)) if not user_ids and not email.address: # This state doesn't make sense, so something must be mutating, # or in the process of deleting, the object. We assume it will bring # things to a correct state, and we just do nothing except logging this event. logger.warning("ScheduledEmail id %s has empty users and address attributes.", email.id) return if user_ids: data["to_user_ids"] = user_ids if email.address is not None: data["to_emails"] = [email.address] handle_send_email_format_changes(data) send_email(**data) email.delete()