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

Handle updated exception signature from super validate method. #11770

Merged
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
12 changes: 8 additions & 4 deletions kolibri/plugins/user_profile/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from django.core.management import call_command
from morango.errors import MorangoError
from rest_framework import serializers
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.exceptions import ValidationError
from rest_framework.status import HTTP_201_CREATED

from .utils import TokenGenerator
from kolibri.core import error_constants
from kolibri.core.auth.constants import role_kinds
from kolibri.core.auth.models import FacilityUser
from kolibri.core.auth.tasks import PeerImportSingleSyncJobValidator
Expand Down Expand Up @@ -40,9 +41,12 @@ class MergeUserValidator(PeerImportSingleSyncJobValidator):
def validate(self, data):
try:
job_data = super(MergeUserValidator, self).validate(data)
except AuthenticationFailed:
self.create_remote_user(data)
job_data = super(MergeUserValidator, self).validate(data)
except ValidationError as e:
if e.detail.code == error_constants.AUTHENTICATION_FAILED:
self.create_remote_user(data)
job_data = super(MergeUserValidator, self).validate(data)
else:
raise

job_data["kwargs"]["local_user_id"] = data["local_user_id"].id
job_data["extra_metadata"].update(user_fullname=data["local_user_id"].full_name)
Expand Down