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

Allauth: don't completely override the send_email method #11526

Merged
merged 3 commits into from
Aug 29, 2024
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Aug 7, 2024

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 in render_mail to send the message using our task.

@stsewd stsewd marked this pull request as ready for review August 7, 2024 23:19
@stsewd stsewd requested a review from a team as a code owner August 7, 2024 23:19
@stsewd stsewd requested a review from humitos August 7, 2024 23:19
Copy link
Member

@humitos humitos left a 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.
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Comment on lines -23 to -25
def send_mail(self, template_prefix, email, context):
subject = render_to_string(
"{}_subject.txt".format(template_prefix),
Copy link
Member

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.

Copy link
Member Author

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.

@stsewd stsewd requested a review from humitos August 27, 2024 16:53
readthedocs/core/utils/__init__.py Show resolved Hide resolved
@stsewd stsewd enabled auto-merge (squash) August 29, 2024 16:23
@stsewd stsewd disabled auto-merge August 29, 2024 16:24
@stsewd stsewd merged commit f0aaff2 into main Aug 29, 2024
5 of 6 checks passed
@stsewd stsewd deleted the allauth-email branch August 29, 2024 16:32
humitos added a commit that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants