From 8402bd49d49d928d6b0b667e9844d49c56e035de Mon Sep 17 00:00:00 2001 From: Aram Dulyan Date: Tue, 17 Aug 2021 17:08:22 +1000 Subject: [PATCH 1/2] Prevent conflicts with e-mail backends where send_messages() return lists --- bandit/backends/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bandit/backends/base.py b/bandit/backends/base.py index a9e298f..29500b6 100644 --- a/bandit/backends/base.py +++ b/bandit/backends/base.py @@ -79,7 +79,7 @@ def is_approved(email): # can report them as sent to the caller logged_count += 1 sent_count = super().send_messages(to_send) or 0 - return sent_count + logged_count + return logged_count + (len(sent_count) if hasattr(sent_count, "__len__") else sent_count) class LogOnlyBackendMixin(HijackBackendMixin): From 1edf2bf2bd0df4eb0679ed61c4d3d21cad49e0bb Mon Sep 17 00:00:00 2001 From: Aram Dulyan Date: Fri, 5 Nov 2021 19:46:41 +1100 Subject: [PATCH 2/2] Add suggested documentation for workaround Co-authored-by: Tobias McNulty --- bandit/backends/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bandit/backends/base.py b/bandit/backends/base.py index 29500b6..61e1247 100644 --- a/bandit/backends/base.py +++ b/bandit/backends/base.py @@ -79,6 +79,8 @@ def is_approved(email): # can report them as sent to the caller logged_count += 1 sent_count = super().send_messages(to_send) or 0 + # attempt to workaround backends like django-celery-email that return a list instead of + # a count: https://github.com/pmclanahan/django-celery-email/pull/69 return logged_count + (len(sent_count) if hasattr(sent_count, "__len__") else sent_count)