Skip to content

Add call to generate edX usernames on course run enroll if none exist#3398

Open
jkachel wants to merge 1 commit intomainfrom
jkachel/10536-ensure-openedxuser-on-enroll
Open

Add call to generate edX usernames on course run enroll if none exist#3398
jkachel wants to merge 1 commit intomainfrom
jkachel/10536-ensure-openedxuser-on-enroll

Conversation

@jkachel
Copy link
Contributor

@jkachel jkachel commented Mar 18, 2026

What are the relevant tickets?

Closes mitodl/hq#10536

Description (What does it do?)

Saving an enrollment through the regular v1/enrollments API more-or-less just calls create_run_enrollments, which bails out if there's no edX username. This PR adds a check to see if there is a username for the user, and creates only the username if there isn't one.

How can this be tested?

Automated tests should pass.

Test by:

  1. Sign into Learn with a new user. Do not sign into MITx Online.
  2. Ensure there's no OpenEdxUser for the new user. (The user shouldn't exist at all in MITx Online.)
  3. From Learn, attempt to enroll in a standalone course for audit. This should hit the /api/v1/enrollments endpoint, and that should work.
  4. Check to see that an OpenEdxUser is now created for the user. (It may or may not be synced depending on whether or not you have edX/Tutor set up and running.)
  5. Check to see that there's an enrollment for the user. There should be an audit enrollment for the course run. (Again, it may or may not be synced yet.)

Additional Context

This doesn't do anything for program enrollments because those don't hit edX.

It only makes the edX username because the create_run_enrollments call will ultimately try to repair the user - it just won't get to that point unless there's a username set for them. So, since the repair call always happens, there's already a call to create the user, so there's no need to do it prematurely.

@github-actions
Copy link

github-actions bot commented Mar 18, 2026

OpenAPI Changes

Show/hide ## Changes for v0.yaml:
## Changes for v0.yaml:


## Changes for v1.yaml:


## Changes for v2.yaml:


Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@jkachel jkachel force-pushed the jkachel/10536-ensure-openedxuser-on-enroll branch from 8106b51 to 4582c20 Compare March 18, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant