rusackas opened a new pull request, #40693:
URL: https://github.com/apache/superset/pull/40693

   ### SUMMARY
   
   `EmailNotification.now` was a **class attribute** evaluated once, when the 
module is first imported:
   
   ```python
   class EmailNotification(BaseNotification):
       now = datetime.now(timezone("UTC"))   # frozen at import time
   ```
   
   Two problems flow from this:
   
   1. **Latent product bug:** in a long-running worker, every report email 
rendered with `DATE_FORMAT_IN_EMAIL_SUBJECT` enabled stamps the subject with 
the date the *process started*, not the actual send date. A worker up for 
several days would put a stale date in every alert/report subject.
   2. **Flaky CI:** `test_email_subject_with_datetime` sampled its own 
`datetime.now()` separately from that frozen class attribute. When the 
unit-test job ran across the **UTC midnight boundary**, the two clocks landed 
on different days and the test failed:
   
      ```
      AssertionError: assert '2026-06-03' in '[Report]  test alert 2026-06-02'
      ```
   
      This was simultaneously failing `unit-tests` on several open PRs (#40559, 
#40629, #40632, #40633) whose jobs happened to run near 00:00 UTC — same flake, 
not separate bugs.
   
   ### Changes
   
   - `superset/reports/notifications/email.py`: stamp `self.now` once per 
instance in `__init__` (at send time) instead of once per process at import. 
Each notification now reflects its real creation/send time.
   - `tests/unit_tests/reports/notifications/email_tests.py`: assert against 
the notification's own `now` rather than a separately-sampled clock, so the 
test can't flake at the day boundary. Drops the now-unused 
`datetime`/`timezone` imports.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A
   
   ### TESTING INSTRUCTIONS
   
   ```bash
   python -m pytest tests/unit_tests/reports/notifications/email_tests.py
   ```
   
   3/3 pass. The fixed test no longer depends on wall-clock alignment across 
the midnight boundary.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to