fix(reports): evaluate email subject datetime per send instead of at import#40285
Conversation
Code Review Agent Run #19e9dbActionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40285 +/- ##
=======================================
Coverage 64.16% 64.16%
=======================================
Files 2591 2591
Lines 138293 138296 +3
Branches 32084 32084
=======================================
+ Hits 88736 88738 +2
- Misses 48027 48028 +1
Partials 1530 1530
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The PR comment file contains 1 comment row (excluding the header). Here's the full comment content: "Suggestion: The timestamp is recomputed on every |
…istent subject/attachment names
|
@codeant-ai-for-open-source Good catch — addressed in 5f92915:
Existing test
|
|
Question: - added a
existing test
Answer: A few notes:
One small caveat to keep in mind: with |
SUMMARY
Fixes #35908. The
DATE_FORMAT_IN_EMAIL_SUBJECTfeature was substituting the datetime token (e.g.%c) with a value frozen to the time the worker started, not the time each email was sent. For an hourly scheduled report this means every email arrives with the same subject — defeating the original purpose of the feature (per the original author in #31413: "enabling the email client to correctly thread the emails").Root cause
EmailNotification.nowwas declared as a class attribute:Python evaluates class-body expressions when the class is first imported, so
nowwas effectivelydatetime(worker_start_time)forever._parse_namethen usedself.now.strftime(name)for every email.Fix
nowclass attribute.datetime.now(timezone("UTC"))inside_parse_nameon every call, so each scheduled email picks up the current timestamp.TESTING INSTRUCTIONS
Result locally: 3 passed in 0.73s (existing 2 tests + 1 new regression test).
Manual repro (before the fix):
FEATURE_FLAGS = {"DATE_FORMAT_IN_EMAIL_SUBJECT": True}insuperset_config.py.Hourly Report %c.After the fix: each email's subject shows the actual send time.
Regression test
tests/unit_tests/reports/notifications/email_tests.py::test_email_subject_datetime_evaluated_per_sendpatchesdatetime.nowto return two different times between two_get_subject()calls on the sameEmailNotificationinstance and asserts the resulting subjects differ.ADDITIONAL INFORMATION
DATE_FORMAT_IN_EMAIL_SUBJECT(already exists, unchanged)