django-mailer icon indicating copy to clipboard operation
django-mailer copied to clipboard

TypeError sequence item 1: expected str instance, NoneType found

Open ebdavison opened this issue 3 years ago • 5 comments

Describe the bug When I navigate to the /admin/mailer/messages model I get an error:

sequence item 1: expected str instance, NoneType found

Reproduce behavior

  1. Browse to admin console
  2. scroll to the Mailer section
  3. click on Messages

Expected behavior A list of mail messages show in the admin console.

Screenshots

image

image

Desktop

  • OS: Linux Fedore 34
  • Browser: Chrome
  • Version: 91.0.4472.114

Additional context

  1. I have version 2.0.1 of django-mailer and no recent changes to the modules or DB.
  2. recently email messages are not going out to some recipients so I thought to check here to see what was "in the queue" as a first troubleshooting step.
  3. using python manage.py dbshell I have produced this overview of what is currently in the messages table:
otcomm=> select id, when_added, priority, length(message_data) from mailer_message;
  id  |          when_added           | priority | length
------+-------------------------------+----------+--------
 3113 | 2021-07-15 01:39:01.507631+00 |        2 |   3571
 3114 | 2021-07-15 01:39:07.267681+00 |        2 |   3607
 3115 | 2021-07-15 01:39:17.356411+00 |        2 |   3607
 3116 | 2021-07-15 01:40:24.226602+00 |        2 |  24341
 3117 | 2021-07-15 01:40:24.37943+00  |        2 |  24337
 3118 | 2021-07-15 01:40:24.432375+00 |        2 |  24328
 3119 | 2021-07-15 03:46:24.298529+00 |        2 |  24341
 3120 | 2021-07-15 03:46:24.336591+00 |        2 |  24337
 3121 | 2021-07-15 03:46:24.435281+00 |        2 |  24328
 3122 | 2021-07-18 18:00:28.308824+00 |        2 |   1747
 3123 | 2021-07-22 01:49:06.017365+00 |        2 |    762
 3124 | 2021-07-22 01:53:26.389339+00 |        2 |    770
 3125 | 2021-07-22 02:08:05.236359+00 |        2 |    770
 3126 | 2021-07-22 02:10:43.201255+00 |        2 |    770
(14 rows)

ebdavison avatar Jul 22 '21 15:07 ebdavison

I did a little bit more digging and found the following that had a None in one of the values.

image

Not sure how it got in there nor how to fix it so I just removed it with delete() and now I can get a list again...

Any thoughts on how to fix this or even better a way for the function to NOT error 500 when a None is returned?

ebdavison avatar Jul 26 '21 17:07 ebdavison

We could fix the admin by doing:

return ", ".join(map(str, message.to_addresses))

in the line you identified in the stack trace. If you could test that, that would really help.

In addition to that, you'll need to fix your code to ensure you aren't passing to=None, because that will cause issues down the line anyway.

spookylukey avatar Jul 26 '21 19:07 spookylukey

I can test that. I thought all of my email sending code had a check for None already but I will also check for that as well to prevent future issues.

ebdavison avatar Jul 27 '21 15:07 ebdavison

I have checked by DB and cannot find any email address records that are empty (None) so thought the best way to handle this is as recommended.

ebdavison avatar Sep 15 '22 22:09 ebdavison

I have a PR open on this; any chance it can be reviewed?

ebdavison avatar Oct 07 '22 23:10 ebdavison