Revert migration update as it creates more issues than it fixes.

This commit is contained in:
Saleem Latif
2020-11-19 11:25:16 +05:00
parent 1be64fc928
commit 54f59bc3b4
3 changed files with 15 additions and 4 deletions

View File

@@ -15,9 +15,9 @@ from completion.utilities import get_key_to_last_completed_block
from django.conf import settings
from django.contrib.auth import load_backend
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.validators import ValidationError
from django.db import IntegrityError, transaction
from django.db import IntegrityError, transaction, ProgrammingError
from django.urls import NoReverseMatch, reverse
from django.utils.translation import ugettext as _
from pytz import UTC
@@ -726,3 +726,14 @@ def get_resume_urls_for_enrollments(user, enrollments):
url_to_block = ''
resume_course_urls[enrollment.course_id] = url_to_block
return resume_course_urls
def does_user_profile_exist(user):
"""
Check if user has an associated profile.
Ignore errors and return False in case of errors.
"""
try:
return hasattr(user, 'profile')
except (ProgrammingError, ObjectDoesNotExist):
return False

View File

@@ -26,7 +26,6 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('user_api', '0002_retirementstate_userretirementstatus'),
('student', '0033_userprofile_state'),
]
operations = [

View File

@@ -26,6 +26,7 @@ from lms.djangoapps.email_marketing.tasks import (
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from openedx.core.djangoapps.user_authn.cookies import CREATE_LOGON_COOKIE
from openedx.core.djangoapps.user_authn.views.register import REGISTER_USER
from common.djangoapps.student.helpers import does_user_profile_exist
from common.djangoapps.student.signals import SAILTHRU_AUDIT_PURCHASE
from common.djangoapps.util.model_utils import USER_FIELD_CHANGED
@@ -174,7 +175,7 @@ def email_marketing_user_field_changed(sender, user=None, table=None, setting=No
return
# Ignore users that do not yet have a profile
if not hasattr(user, 'profile'):
if not does_user_profile_exist(user):
return
# ignore anything but User, Profile or UserPreference tables