From a80cf6dbc355727079f12ca95436bd453abe1d60 Mon Sep 17 00:00:00 2001 From: Jared Lewis Date: Wed, 2 Jun 2021 13:11:28 -0400 Subject: [PATCH] Bugfix for not marking emails as sent when no emails exist --- entity_emailer/interface.py | 3 +++ entity_emailer/tests/interface_tests.py | 16 ++++++++++++++-- entity_emailer/version.py | 2 +- release_notes.rst | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/entity_emailer/interface.py b/entity_emailer/interface.py index 4ae4246..e5dfe9a 100644 --- a/entity_emailer/interface.py +++ b/entity_emailer/interface.py @@ -56,7 +56,10 @@ def send_unsent_scheduled_emails(cls): to_email_addresses = get_subscribed_email_addresses(email) # If there are no recipients we can just skip rendering + # and mark the email as sent if not to_email_addresses: + email.sent = current_time + email.save(update_fields=['sent']) continue # If any exceptions occur we will catch the exception and store it as a reference diff --git a/entity_emailer/tests/interface_tests.py b/entity_emailer/tests/interface_tests.py index e1a3b44..eda7dde 100644 --- a/entity_emailer/tests/interface_tests.py +++ b/entity_emailer/tests/interface_tests.py @@ -391,11 +391,23 @@ def setUp(self): def test_sends_all_scheduled_emails_no_email_addresses(self, render_mock, address_mock): render_mock.return_value = ['

This is a test html email.

', 'This is a test text email.'] address_mock.return_value = [] - g_email(context={}, scheduled=datetime.min) - g_email(context={}, scheduled=datetime.min) + original_emails = [ + g_email(context={}, scheduled=datetime.min), + g_email(context={}, scheduled=datetime.min) + ] EntityEmailerInterface.send_unsent_scheduled_emails() self.assertEqual(len(mail.outbox), 0) + # Assert that the emails are still marked as sent + sent_emails = Email.objects.filter( + id__in=[email.id for email in original_emails], + sent__isnull=False + ) + self.assertEqual( + set(sent_emails), + set(original_emails) + ) + @override_settings(DISABLE_DURABILITY_CHECKING=True) @patch('entity_emailer.interface.get_subscribed_email_addresses') @patch.object(Event, 'render', spec_set=True) diff --git a/entity_emailer/version.py b/entity_emailer/version.py index 55fa725..f811561 100644 --- a/entity_emailer/version.py +++ b/entity_emailer/version.py @@ -1 +1 @@ -__version__ = '2.1.1' +__version__ = '2.1.2' diff --git a/release_notes.rst b/release_notes.rst index 17403cd..c17705e 100644 --- a/release_notes.rst +++ b/release_notes.rst @@ -1,6 +1,10 @@ Release Notes ============= +v2.1.2 +------ +* Fix issue for not marking email as sent when no email addresses exist + v2.1.1 ------ * Fixed error handling with email backend exceptions that implement to_dict