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

Add transaction.on_commit to send_email task #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions django_ses_plus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db import models, transaction
from django.template.loader import render_to_string
from django.utils import translation
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -51,12 +51,14 @@ def send_email(self, subject, template_path, context, from_email=None, language=
translation.activate(language)

html_message = render_to_string(template_path, context)
send_email.delay(
subject=subject,
to_email=self.get_to_email(),
html_message=html_message,
from_email=from_email,
recipient_id=recipient_id
transaction.on_commit(
lambda: send_email.delay(
subject=subject,
to_email=self.get_to_email(),
html_message=html_message,
from_email=from_email,
recipient_id=recipient_id
)
)

if language:
Expand Down