Skip to content
Snippets Groups Projects
Commit 4a3f9b89 authored by Saleem Latif's avatar Saleem Latif
Browse files

Do not send email if profile not created, this code path is run as a result...

Do not send email if profile not created, this code path is run as a result UserPreference save signal before profile is created.
parent 161c0890
No related branches found
No related tags found
No related merge requests found
......@@ -173,6 +173,10 @@ def email_marketing_user_field_changed(sender, user=None, table=None, setting=No
if user.is_anonymous:
return
# Ignore users that do not yet have a profile
if not hasattr(user, 'profile'):
return
# ignore anything but User, Profile or UserPreference tables
if table not in {'auth_user', 'auth_userprofile', 'user_api_userpreference'}:
return
......
......@@ -30,7 +30,7 @@ from lms.djangoapps.email_marketing.tasks import (
update_user_email
)
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from common.djangoapps.student.models import Registration
from common.djangoapps.student.models import Registration, User
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, UserProfileFactory
from common.djangoapps.util.json_request import JsonResponse
......@@ -336,6 +336,10 @@ class EmailMarketingTests(TestCase):
email_marketing_user_field_changed(None, user=anon)
self.assertFalse(mock_log_error.called)
user = User(username='test', email='test@example.com')
email_marketing_user_field_changed(None, user=user)
self.assertFalse(mock_log_error.called)
@patch('lms.djangoapps.email_marketing.tasks.SailthruClient.api_post')
def test_change_email(self, mock_sailthru):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment