Skip to content

Fix empty email destination at cronjob#650

Merged
stephenfin merged 1 commit into
getpatchwork:mainfrom
mchehab:fix_empty_email_fields
Jun 7, 2026
Merged

Fix empty email destination at cronjob#650
stephenfin merged 1 commit into
getpatchwork:mainfrom
mchehab:fix_empty_email_fields

Conversation

@mchehab
Copy link
Copy Markdown
Contributor

@mchehab mchehab commented Jun 6, 2026

If recipient is not filled or is invalid, email submission cronjob crashes 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.

@mchehab mchehab changed the title Fix empty email fields Fix empty email destination at cronjob Jun 6, 2026
@stephenfin stephenfin force-pushed the fix_empty_email_fields branch from c559511 to 5ac6f4e Compare June 7, 2026 15:16
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]
@stephenfin stephenfin force-pushed the fix_empty_email_fields branch from 5ac6f4e to 6095c93 Compare June 7, 2026 15:44
@stephenfin stephenfin merged commit 1139b9a into getpatchwork:main Jun 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants