fix: correct fallback handling for email opt-in report (#38410)#398
Open
ajayakkalasetti wants to merge 1 commit into
Open
fix: correct fallback handling for email opt-in report (#38410)#398ajayakkalasetti wants to merge 1 commit into
ajayakkalasetti wants to merge 1 commit into
Conversation
ajayakkalasetti
marked this pull request as ready for review
July 22, 2026 12:35
kramakrushna
requested review from
Copilot,
kramakrushna,
nakhan-sonata-afk,
ssurendrannair and
subhashree-sahu31
July 22, 2026 13:41
There was a problem hiding this comment.
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_datetimewhen no preference record exists (removes the hardcoded 2014 fallback). - Output empty
is_opted_in_for_emailwhen 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 "", |
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.
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
is_opted_in_for_emailto"True"preference_set_datetimeempty when no value existsis_opted_in_for_emailempty when no preference is setReference: