Skip to content

Commit

Permalink
Merge pull request #11770 from rtibbles/handle_validation_error_for_a…
Browse files Browse the repository at this point in the history
…uth_failure

Handle updated exception signature from super validate method.
  • Loading branch information
marcellamaki authored Jan 23, 2024
2 parents b79aefc + 8092292 commit b53fa42
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit b53fa42

Please sign in to comment.