Repository navigation
feat: delete pathway data on learner retirement (ENT-12476) - #28
Open
sjasti-sonata-svg wants to merge 1 commit into
Open
sjasti-sonata-svg wants to merge 1 commit into
sjasti-sonata-svg wants to merge 1 commit into
Conversation
sjasti-sonata-svg
force-pushed
the
sjasti/ENT-12476-retire-pathway-progress
branch
6 times, most recently
from
November 30, 2026 07:32
515141e to
0e9cdce
Compare
There was a problem hiding this comment.
🟡 Changes recommended
An unguarded in-flight progress update can recreate retired learner data and history after cleanup, while the backlog command caches every matching row’s user ID before batching.
2 open issues
What changed in this PR
This PR adds pathway-data cleanup to the LMS learner-retirement process, supporting enterprise privacy requirements and cleanup of previously retired learners.
Changes:
- Adds a flag-controlled retirement receiver to delete progress, history and memberships, and redact related admin logs.
- Adds a dry-run-first backlog command and retirement checks in enrollment, grade-update and backfill paths.
- Adds retirement tests, removes emails from creation logs, updates privacy annotations and releases version 2.2.0.
| File | Description |
|---|---|
tests/test_retirement.py |
Tests cleanup, redaction, receiver wiring and retired-user checks. |
tests/test_retire_pathway_data_backlog.py |
Tests backlog selection, dry runs, deletion and options. |
test_settings.py |
Enables mock retirement models in tests. |
mock_apps/openedx/core/djangoapps/user_api/models.py |
Defines mock retirement models. |
mock_apps/openedx/core/djangoapps/user_api/migrations/0001_initial.py |
Creates mock retirement tables. |
mock_apps/openedx/core/djangoapps/user_api/migrations/__init__.py |
Initializes the mock migrations package. |
mock_apps/openedx/core/djangoapps/user_api/__init__.py |
Initializes the mock user API package. |
learner_pathway_progress/waffle.py |
Defines the shared retirement kill switch. |
learner_pathway_progress/utilities.py |
Adds retirement queries and guards; removes email logging. |
learner_pathway_progress/signals.py |
Implements cleanup, admin-log redaction and the receiver. |
learner_pathway_progress/models.py |
Corrects model privacy annotations. |
learner_pathway_progress/management/commands/retire_pathway_data_backlog.py |
Adds batched cleanup for completed retirements. |
learner_pathway_progress/apps.py |
Registers the LMS retirement receiver. |
learner_pathway_progress/__init__.py |
Bumps the version to 2.2.0. |
CHANGELOG.rst |
Documents the release changes. |
.annotation_safe_list.yml |
Corrects the history model’s privacy annotations. |
Review effort: Balanced
| ) | ||
| ) | ||
| # Deleting the progress rows writes a final history row each, so the history is deleted afterwards. | ||
| progress_deleted = progress.delete()[1].get(LearnerPathwayProgress._meta.label, 0) |
| """ | ||
| Return the sorted ids of the users who have rows in any of ``tables``. | ||
| """ | ||
| return sorted(set().union(*(rows.values_list('user_id', flat=True) for rows in tables.values()))) |
sjasti-sonata-svg
force-pushed
the
sjasti/ENT-12476-retire-pathway-progress
branch
from
December 1, 2026 04:53
0e9cdce to
6a29185
Compare
Privacy requires a retired learner's pathway progress to be deleted, not kept with a user id (ENT-12470 tech spec EE-9, Privacy Q2). Nothing removed it on retirement. Add a USER_RETIRE_LMS_CRITICAL receiver, registered through the plugin config, that deletes the learner's LearnerPathwayProgress rows, then all their history (the delete writes a final history row), and their LearnerEnterprisePathwayMembership rows, in one transaction. It also blanks the Django admin log entries for those rows (tech spec R3), because a membership's object_repr shows the username; entries of memberships deleted earlier are matched by the exact start of that text. It is behind the enterprise.retirement_receivers_v2 waffle flag, the kill switch shared with edx-enterprise's retirement receivers, and logs only counts and the user id. Add the retire_pathway_data_backlog management command for learners whose retirement finished before the receiver is turned on (status row gone or COMPLETE). Learners still in the cooling-off period, who can cancel, are left alone. It removes the data through the same function and is a dry run unless --commit is passed. Retirement keeps the user row and their enterprise enrollments, so the backfill, the enrollment receiver, grade updates and the existing progress updater now skip users with a UserRetirementRequest, or they would add the deleted rows back. Progress updates save with update_fields, an UPDATE only, so an update that loaded a row before retirement deleted it cannot insert it again. Also log the user id instead of the learner's email in the pathway membership and progress logs, and annotate the progress, history and membership tables as holding a learner id. Bump to 2.2.0.
sjasti-sonata-svg
force-pushed
the
sjasti/ENT-12476-retire-pathway-progress
branch
from
December 4, 2026 14:29
6a29185 to
76c3076
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Jira: ENT-12476 (epic ENT-12470, GDPR learner retirement on the enterprise stack)
When a learner is retired, nothing removed their pathway progress or pathway memberships. Privacy requires this data to be deleted, not kept with a user id (tech spec gap EE-9, Privacy Q2). The
on_delete=CASCADEonuserdoesn't help, because the LMS never deletes the retiredauth_userrow.Changes
USER_RETIRE_LMS_CRITICALreceiverhandle_learner_retirement, registered through the plugin config like the existing receivers. In one transaction it deletes the learner's:LearnerPathwayProgressrows,LearnerEnterprisePathwayMembershiprows.object_reprandchange_message; tech spec R3). A membership'sobject_reprshows the learner's username and would otherwise stay indjango_admin_logafter the row is deleted. Progress ids come from the history as well, so entries for progress rows already deleted in the admin are covered too. Memberships keep no history, so entries of memberships deleted earlier are matched by the exact start of their text,User: <username>, Pathway UUID:(the LMS replaces the username only after sending the signal, and usernames can't hold a comma, so another learner can't match). The log entries themselves are kept for the audit trail.user.id, which the signal already sends, so it doesn't depend on any LMS change. It logs only counts and the user id, and a second run finds nothing.LearnerPathwayProgress.update_pathway_progress), and no row refers to another learner's row, so deleting a retired learner's rows doesn't change anyone else's progress (the tests check other learners' rows are untouched). Counts computed elsewhere from these tables (for example reports) drop by that learner, as intended.auth_userrow and the learner's enterprise enrollments, so four paths could add the deleted rows back: theupdate_all_pathways_progressbackfill, theEnterpriseCourseEnrollmentpost_save receiver, grade updates, andupdate_existing_pathways_progress. All four now skip users with aUserRetirementRequest(edx-platform keeps those rows after the retirement completes;UserRetirementStatusrows are deleted by the cleanup step). The tests use small stand-ins for the LMS modelsUserRetirementRequest,RetirementStateandUserRetirementStatusinmock_apps. This check is not behind the flag: skipping retired users is always correct, and it costs one indexed lookup. It includes learners in the cooling-off period, which is fine for not creating data. If the LMS retirement models can't be imported, a warning is logged at startup.update_existing_pathways_progressloads all progress rows, then updates them one by one; a learner retired meanwhile still had their row saved from the stale copy, and a plainsave()falls back to INSERT, recreating the row and its history.update_pathway_progressnow saves withupdate_fields, which is an UPDATE only: on a deleted row Django raisesDatabaseErrorinstead of inserting. The updater runs each row in its own savepoint, skips (and logs) a row deleted this way, and re-raises any other database error. No lock is needed: the UPDATE either commits before the retirement deletes the row, or finds no row.retire_pathway_data_backlogfor learners retired before the receiver is turned on (the receiver only sees new retirements; ENT-12489's backlog command covers only the enterprise services). It finds learners whose retirement has finished (they have aUserRetirementRequest, and theirUserRetirementStatusis gone orCOMPLETE) who still have pathway progress, history or memberships, and removes them with the sameretire_learner_pathway_dataas the receiver, one learner per transaction. Learners still in the cooling-off period (PENDING, which can be cancelled) and unfinished retirements are left out; the receiver handles them when their retirement runs. This relies on edx-platform'sremove_pending_retirement_requestreceiver (present onrelease-ulmo): cancelling aPENDINGretirement deletes the status row and, through that receiver, theUserRetirementRequest, so a cancelled learner never looks finished. A retirement that had already passed the LMS step before the flag went on but hasn't finished yet (in progress, errored or aborted) is skipped too. The command logs the skipped learners with pathway data as two counts: those in the cooling-off period (handled by the receiver; in prod this is rarely 0) and those with another unfinished retirement (the only reason to run it again). It reads distinct user ids in the database (default ordering cleared, so a learner's many history rows count once). Dry run by default (logs the number of learners and rows per table);--commitremoves;--batch-size(default 100 learners) and--sleepare validated before anything is removed. Logs only counts. Their usernames were already replaced, so admin log entries of memberships deleted before are not matched by username; those of the rows deleted here are blanked as usual.enterprise.retirement_receivers_v2waffle flag (default off). That is the same flag edx-enterprise defines for its retirement receivers (feat: retire pending invites on learner retirement (ENT-12474) openedx/edx-enterprise#2749), so one flag turns all the enterprise retirement changes on or off. With the flag off, nothing changes.LearnerPathwayProgress, its history andLearnerEnterprisePathwayMembershipwere markedno_pii; they now record thatuserlinks the row to a learner and that it is deleted on retirement.No row holds free text or an email, so there is nothing to blank before deleting. Copies already in the data warehouse are handled by Data Engineering's warehouse work in the same epic (ENT-12490).
Testing
test_signals.py) and a grade update (test_utilities.py) now also run for a retired learner (ddt), who gets no membership or progress and no pathway lookup.tests/test_retirement.py: the backfill creates nothing for a retired learner (it still does for an active learner); with the flag on, the learner's progress, all its history and their memberships are deleted, and the log holds the user id but not the email; other learners' rows, history and admin log entries are untouched; the admin log entries for the learner's rows (including a progress row already deleted in the admin) are blanked; the plugin config registers the receiver forUSER_RETIRE_LMS_CRITICALwith a function name that exists; a membership deleted earlier has its admin log entry blanked through the username, and a learner whose username starts with this one's is untouched; with the flag off nothing changes (rows, history and admin log); a second run deletes nothing.update_existing_pathways_progressskips a row deleted after it loaded it (other learners still updated) and a retired learner's rows, and re-raises other database errors. Both race tests fail with the old plainsave().tests/test_retire_pathway_data_backlog.py: the dry run reports per-table counts and the skipped learners as two counts (cooling-off, other unfinished), and removes nothing;--commitremoves only the data of learners whose retirement finished (status row gone orCOMPLETE), and keeps that of a learner in the cooling-off period (PENDING), an errored retirement and an active learner; a second run finds nothing; sleeps between batches; invalid--batch-size/--sleep(-1,nan,inf) are rejected before anything is removed.Rollout
learner-pathway-progressinedx/edx-internal(argocd/applications/edxapp-lms/requirements/private_requirements.txt).enterprise.retirement_receivers_v2with Everyone: Yes on stage, retire a test learner, then prod. To roll back, turn the flag off. Use Everyone: Yes, not staff-only or a percentage: the same flag also switches edx-enterprise's scheduledremove_expired_pending_group_membershipsjob, which has no request and so sees the flag as on only when it is on for everyone../manage.py lms retire_pathway_data_backlog(dry run) on stage, check the counts, then run it with--committhere.--commitin prod, check that every retired learner has aUserRetirementRequest(learners retired before that model existed, or through a path that didn't create one, would be missed). First check that prod'sRETIRED_EMAIL_FMTis stillretired__user_{}@retired.invalid. Then run this on a read replica:missed_with_pathway_datais above 0, those learners are a known gap, to be noted here.--commit. It is safe to run again.