From 8693d5a4a629ca27d75fc42070fd6a3999531a04 Mon Sep 17 00:00:00 2001 From: Muhammad Bilal Tahir <106396899+bilaltahir21@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:37:11 +0500 Subject: [PATCH] feat: create user profile if not found in current job command --- .../commands/populate_enterprise_learner_current_job.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py b/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py index 18d7d33841..6593556ab8 100644 --- a/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py +++ b/openedx/core/djangoapps/user_api/management/commands/populate_enterprise_learner_current_job.py @@ -9,7 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.conf import settings from django.core.management.base import BaseCommand -from common.djangoapps.student.models import User +from common.djangoapps.student.models import User, UserProfile from openedx.core.djangoapps.user_api import errors LOGGER = logging.getLogger(__name__) @@ -66,10 +66,12 @@ class Command(BaseCommand): Helper method to return the user profile object based on username. """ try: - user = User.objects.filter(username=username).select_related('profile').first() + existing_user = User.objects.get(username=username) except ObjectDoesNotExist: raise errors.UserNotFound() # lint-amnesty, pylint: disable=raise-missing-from - return user.profile + + existing_user_profile, _ = UserProfile.objects.get_or_create(user=existing_user) + return existing_user_profile def _update_current_job_of_learner(self, username, current_job): """