Abdulrehman-PIAIC80387 opened a new pull request, #40285:
URL: https://github.com/apache/superset/pull/40285
### SUMMARY
Fixes #35908. The `DATE_FORMAT_IN_EMAIL_SUBJECT` feature 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.now` was declared as a **class attribute**:
```python
class EmailNotification(BaseNotification):
type = ReportRecipientType.EMAIL
now = datetime.now(timezone("UTC")) # evaluated ONCE at module import
time
```
Python evaluates class-body expressions when the class is first imported, so
`now` was effectively `datetime(worker_start_time)` forever. `_parse_name` then
used `self.now.strftime(name)` for every email.
### Fix
- Remove the `now` class attribute.
- Compute `datetime.now(timezone("UTC"))` inside `_parse_name` on every
call, so each scheduled email picks up the current timestamp.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/reports/notifications/email_tests.py -v
```
Result locally: 3 passed in 0.73s (existing 2 tests + 1 new regression test).
Manual repro (before the fix):
1. Set `FEATURE_FLAGS = {"DATE_FORMAT_IN_EMAIL_SUBJECT": True}` in
`superset_config.py`.
2. Create an hourly scheduled report with an email subject containing a
strftime token, e.g. `Hourly Report %c`.
3. Receive two consecutive hourly emails — both subjects show the worker's
start time, not the send time.
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_send`
patches `datetime.now` to return two different times between two
`_get_subject()` calls on the same `EmailNotification` instance and asserts the
resulting subjects differ.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #35908
- [ ] Required feature flags: `DATE_FORMAT_IN_EMAIL_SUBJECT` (already
exists, unchanged)
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]