django-mailer
django-mailer copied to clipboard
TypeError sequence item 1: expected str instance, NoneType found
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
- Browse to admin console
- scroll to the Mailer section
- click on Messages
Expected behavior A list of mail messages show in the admin console.
Screenshots
Desktop
- OS: Linux Fedore 34
- Browser: Chrome
- Version: 91.0.4472.114
Additional context
- I have version 2.0.1 of
django-mailer
and no recent changes to the modules or DB. - 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.
- 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)
I did a little bit more digging and found the following that had a None
in one of the values.
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?
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.
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.
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.
I have a PR open on this; any chance it can be reviewed?