Repository navigation
fix(reports): fail closed on alert screenshot capture instead of delivering a blank - #43031
Conversation
…vering a blank Scheduled alerts that attach a dashboard/chart screenshot (PNG/PDF) could deliver a blank or partial image on large or slow-rendering dashboards, while reports were protected. Root cause: `AsyncExecuteReportScheduleCommand.run()` built a `ReportExecutionContext` only for `type == REPORT`. Alerts ran with `report_execution_context=None`, which in `take_tiled_screenshot` selects the lenient readiness predicate (`CHART_HOLDERS_READY_JS` instead of `REPORT_CHART_HOLDERS_READY_JS`) and sets `allow_partial_fallback=True`, so partial/blank tiles were combined and delivered instead of failing. Fix: route alerts that deliver a rendered screenshot (PNG/PDF with `ALERTS_ATTACH_REPORTS` enabled) through the same execution context reports use, so a blank/incomplete capture raises `ReportScheduleScreenshotFailedError` and hands off to the existing retry/notification and error handling. The `type == REPORT` discriminator is replaced with an explicit "delivers a rendered artifact" check (`_should_build_execution_context`). CSV/text alerts, alerts without the attach flag, the non-delivered query-context capture, and UI thumbnails keep their existing lenient behavior; report behavior is unchanged. Also fix a notification asymmetry: `ReportSuccessState` (Success/Grace path) logged ERROR on a send failure but did not notify the owner, unlike the first-run `ReportNotTriggeredErrorState` path. A schedule whose previous run succeeded then failed to deliver would fail silently — the common case once screenshots fail closed. The Success/Grace path now sends the owner error notification (respecting the error grace period), mirroring the first-run path. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Elizabeth Thompson <[email protected]>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43031 +/- ##
==========================================
- Coverage 66.59% 66.55% -0.04%
==========================================
Files 2863 2868 +5
Lines 161734 163131 +1397
Branches 37262 37541 +279
==========================================
+ Hits 107712 108578 +866
- Misses 51977 52424 +447
- Partials 2045 2129 +84
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…uccess path - test_success_state_send_failure_notifies_owner now also asserts the final update_report_schedule_and_log records ReportState.ERROR, so the test pins both owner-notify and terminal-state persistence. - Add a parametrized test that, when the Success/Grace path's own error notification (send_error) raises SupersetErrorsException or a generic exception, the REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER placeholder is overwritten with the real failure message before ERROR is logged -- mirroring the first-run (ReportNotTriggeredErrorState) path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #d10244Actionable Suggestions - 0Review 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 |
|
@fitzee this PR may be related to things you're looking at |
aminghadersohi
left a comment
There was a problem hiding this comment.
Approving — this is a careful, well-reasoned fail-closed change with a strong test-to-production ratio, and the one cross-cutting behavior shift is deliberate and covered. CI is green (0 failures) and there are no gating threads. A few non-blocking notes below.
Fail-closed gating (run()) — correct and narrow
_should_build_execution_context keeps reports unchanged and admits alerts only when report_format in (PNG, PDF) and ALERTS_ATTACH_REPORTS is enabled — i.e. exactly the case where a rendered screenshot is delivered to recipients. CSV/text alerts, the non-delivered query-context capture, and thumbnails keep their lenient contract. The parametrized test_should_build_execution_context pins every arm, including the negative ALERT + PNG/PDF + flag off → False case.
I enumerated every statement inside the widened if block and each is genuinely type-agnostic: resolve_report_execution_budget_seconds reads the shared working_timeout; deadline/expected_chart_count/ReportExecutionContext are built from shared fields (dashboard, chart_id, config reserves); the report_execution_start log is pure. The only report-only side effect — persist_owned_report_execution_terminal_error — is double-gated (owns_report_working_state re-guarded to type == REPORT, and the except handlers independently check type == REPORT), so alerts never reach terminal-error persistence. One re-guard plus the pre-existing type checks in the except arms = the sweep looks complete.
Success/Grace-path notification (next()) — deliberate, but broader than the title
The new notification block is gated only by is_in_error_grace_period() — not by flag, type, or format. So every report and alert whose previous run succeeded and whose next run fails for any reason now notifies its owner, where it previously stayed silent. This is the intended point of the change (a fail-closed alert that dies silently is the real hazard) and the error grace period throttles repeats, so it isn't a spam vector. I read it as correct — but it's a deployment-wide change in error-notification volume that isn't obvious from the title. Worth a line in the PR description (and arguably UPDATING.md). Doc nit, not a code finding.
Root cause stays discoverable
The first write logs error_message=str(first_ex) by promoting the in-flight WORKING row to ERROR. The marker write in the finally doesn't find a WORKING row to reuse, so create_log inserts a distinct terminal row (as its docstring documents) — the real root-cause message survives in the first ERROR log row, and first_ex is re-raised so it also surfaces in the Celery-level exception. Not buried.
Exception flow — verified end to end
Walked every path: send_error success → marker; SupersetErrorsException → joined messages; ReportScheduleUnexpectedError → warn + keep marker; other → str(); finally logs, then the bare raise re-raises the original first_ex (confirmed by test_success_state_send_failure_notifies_owner, which asserts the original blank screenshot error propagates). No path can swallow the failure and report success — the raise sits outside the grace-period if.
Non-blocking nit (finally catch breadth)
The marker finally catches only ReportScheduleUnexpectedError, whereas the first ERROR write in the same method catches (ReportScheduleUnexpectedError, SQLAlchemyError). create_log wraps the realistic StaleDataError into ReportScheduleUnexpectedError (caught), so the common case is fine, and this mirrors the existing ALERT-branch finally. The only exposure is a rare non-StaleData SQLAlchemyError on the second commit masking first_ex — the run still fails closed, only root-cause fidelity is lost. Optional: widen to match the first write for consistency.
Tests
Reverting the production hunks breaks the module import (_should_build_execution_context) and fails test_success_state_send_failure_notifies_owner (both REPORT and ALERT) and test_success_state_send_error_failure_overwrites_marker — the suite pins the new behavior, including the negative flag-off case and the grace-period suppression case. 176 test lines against 72 production lines is well spent here.
Nice work — the rationale comments and the parametrized coverage made this easy to verify.
SUMMARY
Scheduled alerts that attach a dashboard/chart screenshot (PNG/PDF) could deliver a blank or partial image on large or slow-rendering dashboards, while scheduled reports were already protected.
Root cause.
AsyncExecuteReportScheduleCommand.run()built aReportExecutionContextonly whentype == REPORT. Alerts ran withreport_execution_context=None, and insuperset/utils/screenshot_utils.pythatNone:CHART_HOLDERS_READY_JS) instead of the fail-closedREPORT_CHART_HOLDERS_READY_JS, andallow_partial_fallback=True,so partial/blank tiles were combined and delivered instead of failing.
Fix. Route alerts that deliver a rendered screenshot (PNG/PDF with
ALERTS_ATTACH_REPORTSenabled) through the same execution context reports use, so a blank/incomplete capture raisesReportScheduleScreenshotFailedErrorand hands off to the existing retry/notification and error-handling machinery. Thetype == REPORTdiscriminator is replaced with an explicit "delivers a rendered artifact" check (_should_build_execution_context).Deliberately left unchanged / lenient: CSV/text alerts, alerts without the attach flag, the non-delivered query-context capture (used to force a chart's saved query context), and UI thumbnails. Report behavior is unchanged (reports still always run under a context, regardless of format).
Secondary fix.
ReportSuccessState(the Success/Grace path) loggedERRORon a delivery failure but did not notify the owner, unlike the first-runReportNotTriggeredErrorStatepath which callssend_error(). A schedule whose previous run succeeded and then failed to deliver would fail silently — the common case once screenshots fail closed. The Success/Grace path now sends the owner error notification (respecting the error grace period), mirroring the first-run path.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable (no UI change).
TESTING INSTRUCTIONS
Automated (unit):
_should_build_execution_contextisTruefor all reports and for PNG/PDF alerts whenALERTS_ATTACH_REPORTSis enabled;Falsefor CSV/text/xlsx alerts and for alerts with the flag off — seetest_should_build_execution_context.test_success_state_send_failure_notifies_ownerandtest_success_state_send_failure_skips_notification_in_error_grace.tests/unit_tests/utils/test_screenshot_utils.py.Run:
pytest tests/unit_tests/commands/report/ \ tests/unit_tests/utils/test_screenshot_utils.py \ tests/unit_tests/utils/test_report_execution.py \ tests/unit_tests/reports/Manual: configure an alert with a PNG/PDF screenshot attachment (
ALERTS_ATTACH_REPORTSon) against a large/slow dashboard. Instead of emailing a blank image, the execution now fails closed and follows the schedule's configured retry/error-notification behavior.ADDITIONAL INFORMATION
ALERTS_ATTACH_REPORTS(governs whether alerts attach a rendered screenshot; the fail-closed path applies only when it is enabled)