]> git.ipfire.org Git - thirdparty/patchwork.git/commit
notifications.py: don't crash if notifications recipient is invalid
authorMauro Carvalho Chehab <mchehab@kernel.org>
Tue, 30 Jan 2024 08:22:09 +0000 (08:22 +0000)
committerStephen Finucane <stephen@that.guru>
Wed, 10 Jun 2026 12:44:57 +0000 (13:44 +0100)
commita1540caca8590f3735a2fb80342653a347940c9a
tree0c2d23cf7aa58d7e07531781438ab8bcdad20dd7
parent7074e4b75fcbaa08c5a203a45c9a56a5ecb7a890
notifications.py: don't crash if notifications recipient is invalid

On Django 3:3.2.19, if recipient is not filled or is invalid, cron
job fails with:

  Traceback (most recent call last):
    File "/usr/local/patchwork/./manage.py", line 17, in <module>
      execute_from_command_line(sys.argv)
    File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
      utility.execute()
    File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 413, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 354, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 398, in execute
      output = self.handle(*args, **options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/patchwork/patchwork/management/commands/cron.py", line 19, in handle
      errors = send_notifications()
               ^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/patchwork/patchwork/notifications.py", line 84, in send_notifications
      message.send()
    File "/usr/lib/python3/dist-packages/django/core/mail/message.py", line 284, in send
      return self.get_connection(fail_silently).send_messages([self])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/django/core/mail/backends/smtp.py", line 109, in send_messages
      sent = self._send(message)
             ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/django/core/mail/backends/smtp.py", line 122, in _send
      recipients = [sanitize_address(addr, encoding) for addr in email_message.recipients()]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/django/core/mail/backends/smtp.py", line 122, in <listcomp>
      recipients = [sanitize_address(addr, encoding) for addr in email_message.recipients()]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/django/core/mail/message.py", line 99, in sanitize_address
      address_parts = nm + localpart + domain
                      ~~~^~~~~~~~~~~
  TypeError: can only concatenate str (not "NoneType") to str

As there's no point trying to send a notification to an invalid
e-mail, just drops it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Co-authored-by: Stephen Finucane <stephen@that.guru>
[stephenfin: Updated to fix linter issues]
(cherry picked from commit 1139b9ae0e09e589073c506d4209dea865621eb1)
patchwork/notifications.py