Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mails keep queued on unexpected errors #181

Open
eht16 opened this issue Nov 27, 2024 · 2 comments
Open

Mails keep queued on unexpected errors #181

eht16 opened this issue Nov 27, 2024 · 2 comments
Labels

Comments

@eht16
Copy link
Contributor

eht16 commented Nov 27, 2024

The default error handler (via MAILER_EMAIL_BACKEND setting) will log an info message and defer the mail if the error was one of the expected smtplib or socket errors.
This is fine.

On any other errors, the original exception is raised to make the user aware of the error.
Basically this is also fine but unfortunately breaks (probably intentionally) the loop over all queued mails in engine.send_all(). This leads to having all other queued mails to be unprocessed once an unexpected error occurs.

We actually experienced such a case recently where our code generated an invalid email which caused a ValueError in django.core.mail.message.sanitize_address and then all later queued mails were not processed anymore and the queue grew accordingly.

I see that this is basically intended behavior but I wonder if the above mentioned consequences are actually known.

For now, I overridden the default error handler to not raise an exception on unexpected errors but log them with error log level to get noticed but not break the processing of other mails in the queue.

@spookylukey are you open to PRs changing the current behavior and if so, do you have a preferred way of handling unexpected errors?

@eht16 eht16 added the question label Nov 27, 2024
@spookylukey
Copy link
Contributor

There is a difficulty with knowing what kind of errors can be produced, especially when different backends could all raise different exceptions. Have you looked at https://github.com/pinax/django-mailer/blob/master/docs/usage.rst#error-handling and is it not sufficient for your needs?

If the question is about changing the default behaviour, the answer depends on what changes you are suggesting :-)

I'm wary of changing behaviour that could cause more breakage in some other way for other users. For example, ignoring more exceptions, such as ignoring ValueError by default, which could include almost anything, could result in other undesirable behaviour, like repeatedly trying something (e.g. some external service) which is not going to work, potentially using up money or other resources.

If I was designing from the blank sheet I might do it differently, but there is value in known behaviour at this point.

@eht16
Copy link
Contributor Author

eht16 commented Nov 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants