Skip to content

Commit 3231441

Browse files
committed
feedback + deps error fix
1 parent ae63a7a commit 3231441

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

openedx/api.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _set_edx_error(open_edx_user, data):
265265
open_edx_user.save()
266266

267267

268-
def _create_edx_user_request(open_edx_user, user, access_token): # noqa: C901
268+
def _create_edx_user_request(open_edx_user, user, access_token): # noqa: C901, PLR0915
269269
"""
270270
Handle the actual user creation request to Open edX with retry logic for duplicate usernames.
271271
@@ -314,7 +314,7 @@ def _create_edx_user_request(open_edx_user, user, access_token): # noqa: C901
314314
try:
315315
resp = None
316316
data = None
317-
317+
tried_duplicate_email_fix = False
318318
while attempt < max_attempts:
319319
attempt += 1
320320

@@ -335,6 +335,21 @@ def _create_edx_user_request(open_edx_user, user, access_token): # noqa: C901
335335

336336
data = _parse_openedx_response(resp)
337337

338+
# Only try for LTI user duplicate email error fix if the response error was duplicate-email
339+
if _is_duplicate_email_error(resp, data):
340+
client = get_edx_api_lti_dup_email_client()
341+
dup_email_fix_resp = client.fix_lti_user(
342+
email=user.email, username=current_username
343+
)
344+
# If the LTI API fixed the duplicate email issue, Retry account creation
345+
if (
346+
dup_email_fix_resp.status_code == status.HTTP_200_OK
347+
and not tried_duplicate_email_fix
348+
):
349+
tried_duplicate_email_fix = True
350+
continue
351+
break
352+
338353
new_username, should_continue, should_reset_attempts = (
339354
_handle_username_collision(
340355
resp,
@@ -351,17 +366,6 @@ def _create_edx_user_request(open_edx_user, user, access_token): # noqa: C901
351366
if should_reset_attempts:
352367
attempt = 0
353368
continue
354-
355-
# Only try for LTI user duplicate email error fix if the response error was duplicate-email
356-
if _is_duplicate_email_error(resp, data):
357-
client = get_edx_api_lti_dup_email_client()
358-
dup_email_fix_resp = client.fix_lti_user(
359-
email=user.email, username=current_username
360-
)
361-
# If the LTI API fixed the duplicate email issue, Retry account creation
362-
if dup_email_fix_resp.status_code == status.HTTP_200_OK:
363-
continue
364-
break
365369
break
366370

367371
if _is_bad_request(resp):

openedx/api_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ def test_create_edx_user_409_errors(settings, error_data, lti_fix_response_statu
288288
assert resp1.call_count == 0
289289
if is_duplicate_email:
290290
if lti_fix_response_status == status.HTTP_200_OK:
291-
# The registration will be retried again after the LTI fix and since the loops
292-
# runs 4 times it will run 4 times
293-
assert resp2.call_count == 4
294-
assert resp3.call_count == 4
291+
# The registration is be retried once again after the LTI fix
292+
assert resp2.call_count == 2
293+
assert resp3.call_count == 2
295294
else:
296295
assert resp2.call_count == 1
297296
assert resp3.call_count == 1

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)