Skip to content

fix: skip header row in retire_user CSV - #422

Closed
rahulkanneri-2u wants to merge 1 commit into
release-ulmofrom
boms-717-skip-retire-user-csv-header
Closed

fix: skip header row in retire_user CSV#422
rahulkanneri-2u wants to merge 1 commit into
release-ulmofrom
boms-717-skip-retire-user-csv-header

Conversation

@rahulkanneri-2u

Copy link
Copy Markdown

Description

Updates the retire_user management command to skip a CSV header row when the first two columns are username,email or username,user_email.

This fixes a Stage retire_users_from_csv failure where the command treated the header row as a real user and failed with:

Could not find users with specified username and email address: [{'username': 'email'}]

Impact: Operators running the retirement management command with a CSV file can now use a CSV that includes a standard header row. No learner-facing UI impact.

Supporting information

Private Jira: BOMS-717

Testing instructions

  1. Create a CSV with a header row and one valid user:

    username,email
    <username>,<email>
  2. Run:

    python manage.py lms retire_user --user_file <path-to-file>
  3. Confirm the command skips the header row and processes the real user.

Automated coverage added:

  • Added a regression test for retire_user --user_file with a username,email header row.

Local verification:

  • Ran python -m py_compile on the touched command and test files.
  • Targeted pytest could not run locally because this environment is missing kombu during conftest.py import.

Deadline

None

Other information

This does not include the edx-internal cleanup that will eventually re-enable notifications. That can happen after this fix is deployed to Stage and the retire_users_from_csv job is confirmed passing.

No migrations, UI changes, or accessibility concerns.

Copilot AI lite review requested due to automatic review settings August 11, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the retire_user management command to tolerate a standard CSV header row so operator-provided user retirement CSVs don’t fail when the first row is username,email or username,user_email.

Changes:

  • Skip CSV header rows matching username,email or username,user_email when reading --user_file.
  • Add a regression test ensuring a CSV with a username,email header row is processed successfully.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
openedx/core/djangoapps/user_api/management/commands/retire_user.py Adds logic to detect and skip supported CSV header rows.
openedx/core/djangoapps/user_api/management/tests/test_retire_user.py Adds regression coverage for running retire_user with a header row in the CSV.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 70 to +74
userdata = record.split(',')
username = userdata[0].strip()
user_email = userdata[1].strip()
if username.lower() == 'username' and user_email.lower() in ('email', 'user_email'):
continue
Comment on lines +98 to +108
@skip_unless_lms
def test_successful_retire_with_userfile_header(
setup_retirement_states
): # lint-amnesty, pylint: disable=redefined-outer-name, unused-argument
user = UserFactory.create(username='header-user', email="header-user@example.com")
username = user.username
user_email = user.email
with open(user_file, 'w', newline='') as file:
write = csv.writer(file)
write.writerow(['username', 'email'])
write.writerow([username, user_email])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants