-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Allauth: don't completely override the send_email
method
#11526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine; but I need to take a deeper look at the underlying code that we are overwriting here first.
subject = self.format_email_subject(subject) | ||
def render_mail(self, template_prefix, email, context, headers=None): | ||
""" | ||
Wrapper around render_mail to send emails using a task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to put a link here to the code we are overwriting so it's easy to jump into the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that's useful, you can just use the goto feature from your editor/IDE. Seems more useful to link where .send()
is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just use the goto feature from your editor/IDE
These features are not enabled everywhere -- in particular, when reading code from GitHub.
Seems more useful to link where
.send()
is called.
Yeah, maybe. I want a link to the original code we are overwriting here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are calling super, there is no code being overridden, I'm just wrapping the original response.
These features are not enabled everywhere -- in particular, when reading code from GitHub.
But you don't code using GH. We can't just start linking to code everywhere we call super on external resources. Links to external code get easy out of date. I'd see this being useful if we completely override this method, but we aren't doing so.
def send_mail(self, template_prefix, email, context): | ||
subject = render_to_string( | ||
"{}_subject.txt".format(template_prefix), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a good way to test this in production? I'm worried that we stop sending emails without noticing it -- or we are not picking the correct templates, since I'm seeing here that we are doing something custom for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating an account, resetting a password.
We are overriding the whole
send_mail
method from allauth in order to use our task to send emails, but by doing so is easy to get out of sync with original method from allauth. Instead of overriding the whole method, I'm just creating a wrapper object inrender_mail
to send the message using our task.