pmclanahan / django-celery-email

A Django email backend that uses a celery task for sending the email.
BSD 3-Clause "New" or "Revised" License
477 stars 108 forks source link

fix TypeError that occures during messages sending #69

Open nautics889 opened 4 years ago

nautics889 commented 4 years ago

I encountered a TypeError error during sending messages, because it tried to add an integer and a list in tasks.py. I have been searching for the reason and found a little inconsistency with what Django's documentation suggests:

This method (send_messages(email_messages)) receives a list of EmailMessage instances and returns the number of successfully delivered messages.

So it looked like there was a problem in CeleryEmailBackend.send_messages in backends.py, but when i tried to fix that method and implement returning number of sent messages instead of a list with async results, several tests were failed as the result. Probably, it had had a side-effect for some other cases. So i decided to add a type checking in the tasks.py.

_Note: probably you may also want to look at CeleryEmailBackend.send_messages_

pmac commented 4 years ago

The send_messages method used in tasks.py is one of Django's built in one or a custom one someone else writes. It should not be CeleryEmailBackend.send_messages because that's the one that has caused the task to be run. You make a good point that the send_messages in the celery backend should probably return an integer like the Django docs suggest, but for now it doesn't so that users' code can check the results of the tasks if they need to.