Skip to content

fix: correct fallback handling for email opt-in report (#38410)#398

Open
ajayakkalasetti wants to merge 1 commit into
release-ulmofrom
fix/email-optin-report-fallback-values
Open

fix: correct fallback handling for email opt-in report (#38410)#398
ajayakkalasetti wants to merge 1 commit into
release-ulmofrom
fix/email-optin-report-fallback-values

Conversation

@ajayakkalasetti

@ajayakkalasetti ajayakkalasetti commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Fixes incorrect fallback behavior in the Email Opt-In report where users without an email preference record were assigned misleading default values.

Problem

The report currently assigns:

  • is_opted_in_for_email = "True" (hardcoded)
  • preference_set_datetime = "2014-12-01 00:00:00" (hardcoded default)

when no corresponding record exists in user_api_userorgtag.

Solution

  • Removed the hardcoded fallback date
  • Avoid defaulting is_opted_in_for_email to "True"
  • Instead:
    • Leave preference_set_datetime empty when no value exists
    • Leave is_opted_in_for_email empty when no preference is set

Reference:

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 Email Opt-In report generation to avoid misleading fallback values when a user has no email-optin preference record, aligning the CSV output with the “unknown / unset” state instead of inventing defaults.

Changes:

  • Output empty preference_set_datetime when no preference record exists (removes the hardcoded 2014 fallback).
  • Output empty is_opted_in_for_email when no preference record exists (removes the prior default-to-True behavior).
  • Update test expectations to reflect the new “unset preference => empty field” behavior.

Reviewed changes

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

File Description
openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py Adjusts assertions to expect empty values for unset preferences/datetimes.
openedx/core/djangoapps/user_api/management/commands/email_opt_in_list.py Changes CSV fallback behavior to emit empty fields when preference data is missing.
Comments suppressed due to low confidence (1)

openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py:108

  • This comment still says the user should be opted in by default, but the test now expects an empty value (no preference) for is_opted_in_for_email. Update the comment so it reflects the new behavior.
        # so the user should be opted in by default.
        output = self._run_command(self.TEST_ORG)
        self._assert_output(
            output,
            (self.user, self.courses[0].id, ""),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -68,7 +68,7 @@ def test_enrolled_no_pref(self):
output = self._run_command(self.TEST_ORG)

# By default, if no preference is set by the user is enrolled, opt in
Comment on lines 439 to +443
'course_id': str(course_id),
'is_opted_in_for_email': str(opt_in_pref),
'is_opted_in_for_email': str(opt_in_pref) if isinstance(opt_in_pref, bool) else opt_in_pref,
'preference_set_datetime':
(self._latest_pref_set_datetime(self.user) if kwargs.get('expect_pref_datetime', True) else
self.DEFAULT_DATETIME_STR)} in output[1:]
"")} in output[1:]
"full_name": full_name,
"course_id": course_id,
"is_opted_in_for_email": is_opted_in if is_opted_in else "True",
"is_opted_in_for_email": is_opted_in if is_opted_in else "",

@kramakrushna kramakrushna 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.

Changes looks good for me.

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.

3 participants