rusackas opened a new pull request, #45770: URL: https://github.com/apache/superset/pull/45770
### SUMMARY `superset/utils/dates.py` defines `naive_utcnow()` as "the single clock for naive-UTC datetime columns" — its docstring explains that writing a tz-aware value to a naive-UTC `DateTime` column (e.g. `version_transaction.issued_at`, or the task `started_at`/`ended_at`/`subscribed_at` columns) lets some DB drivers silently convert it to the session-local timezone, skewing every duration computed from it. The helper exists so every writer/comparator of these columns derives its value from one place, making their agreement structural instead of comment-enforced. Despite that, the exact expression `datetime.now(timezone.utc).replace(tzinfo=None)` was still hand-rolled inline 32 times across production code instead of calling `naive_utcnow()`. This PR is a pure mechanical substitution: every inline occurrence of that literal pattern in non-migration code now calls `naive_utcnow()` instead, with no behavior change (same return value). Files changed (production code), with call-site counts replaced: - `superset/commands/report/execute.py` — 26 - `superset/utils/cache.py` — 2 - `superset/commands/deletion_retention/audit.py` — 1 - `superset/commands/logs/prune.py` — 1 - `superset/commands/report/log_prune.py` — 1 (found during a whitespace/line-wrap-tolerant repo scan; this file's single occurrence was split across lines by a prior `black`/`ruff-format` pass and so didn't show up in a naive single-line `grep`) - `superset/daos/log.py` — 1 In each file, the now-unused `timezone` import was dropped where `timezone` wasn't used for anything else in the file; `datetime`/`timedelta` imports were kept where still needed for type hints or arithmetic. Also fixed one test that would have silently stopped testing what it claimed to: `tests/unit_tests/utils/cache_test.py::test_set_and_log_cache_equal_threshold` mocked `superset.utils.cache.datetime` directly (`mock_datetime.now.return_value.replace.return_value.isoformat.return_value = dttm`) to pin a timestamp. Since the code under test no longer calls `datetime.now(...)` itself, that mock is retargeted to `superset.utils.cache.naive_utcnow` (the function the code now actually calls) so the test still pins the timestamp it's asserting against. **Left untouched, as required:** - All occurrences inside `superset/migrations/` (frozen historical snapshots). - `datetime.now(timezone.utc)` calls that do **not** have the trailing `.replace(tzinfo=None)` (mostly `superset/mcp_service/`) — those are deliberately timezone-aware for API response timestamps, a different and correct pattern. - `superset/utils/dates.py` itself (the helper's own implementation). ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF N/A — no UI change. ### TESTING INSTRUCTIONS This is a pure refactor (same return value, same behavior), so no new tests were added. Existing coverage was run: - `tests/unit_tests/commands/report/execute_test.py` — 495 passed - `tests/unit_tests/commands/report/test_execute_now.py`, `execution_claim_test.py`, `executor_test.py` — 67 passed, 26 skipped - `tests/unit_tests/utils/cache_test.py` — 16 passed (including the retargeted mock) - `tests/unit_tests/commands/logs/prune_test.py`, `tests/unit_tests/commands/deletion_retention/test_prune_audit.py` — 121 passed - `pre-commit run` (staged files only) — clean (ruff-format auto-reformatted two files after the substitution; re-staged and re-ran clean) `tests/integration_tests/reports/commands_tests.py::test_prune_log_soft_time_out` was attempted but errors in this environment on a pre-existing, unrelated issue: the local sqlite test DB is missing the `report_schedule.run_as_type` column (a stale test-DB schema, not something this diff touches). ### 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]
