You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2025/10/22 16:45:36 UTC
[PR] fix(reports): improve error handling for report schedule execution [superset]
eschutho opened a new pull request, #35800:
URL: https://github.com/apache/superset/pull/35800
### SUMMARY
This PR fixes critical error handling issues in the report scheduling system that were causing:
1. Confusing cascading errors with redacted "UPDATE" messages
2. Silent error swallowing where failures weren't logged to the dashboard
3. Recursive failures when database logging itself failed
**Root Cause**: When a report schedule is deleted/modified by another process during execution, SQLAlchemy raises `StaleDataError`. The original code didn't handle this, leading to session rollback and subsequent `PendingRollbackError` when trying to access lazy-loaded attributes.
**Changes**:
1. **Handle StaleDataError gracefully** in `create_log()`: Catch the exception, rollback the session, and raise a clear error message that won't be redacted
2. **Fix silent error swallowing** in `ReportSuccessState.next()`: Add missing `raise` statement so errors actually propagate
3. **Prevent recursive logging failures**: Add exception guards around all `update_report_schedule_and_log()` calls to prevent infinite loops when logging itself fails
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend error handling improvement
### TESTING INSTRUCTIONS
1. **Test StaleDataError handling**:
- Start a long-running report execution (e.g., with a slow query)
- Delete the report schedule while it's running
- Verify: Error is logged to `report_execution_log` table with clear message
- Verify: No cascade of `PendingRollbackError` exceptions
2. **Test error propagation**:
- Create a report with a chart that will fail (e.g., broken SQL)
- Run the report
- Verify: Error appears in dashboard logs and system logs
- Verify: Error notification is sent to owners
3. **Test normal execution**:
- Run a successful report
- Verify: No regressions in normal operation
### 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
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2453032123
##########
superset/commands/report/execute.py:
##########
@@ -752,14 +767,21 @@ def next(self) -> None:
return
self.send()
self.update_report_schedule_and_log(ReportState.SUCCESS)
+ except ReportScheduleUnexpectedError:
+ # Don't try to log again if logging itself failed
+ raise
except (SupersetErrorsException, Exception) as first_ex:
error_message = str(first_ex)
if isinstance(first_ex, SupersetErrorsException):
error_message = ";".join([error.message for error in first_ex.errors])
- self.update_report_schedule_and_log(
- ReportState.ERROR, error_message=error_message
- )
+ try:
Review Comment:
From codex:
> When update_report_schedule_and_log raises ReportScheduleUnexpectedError, the bare raise in this except ReportScheduleUnexpectedError clause re-raises the logging failure and short-circuits the outer except (SupersetErrorsException, Exception) as first_ex:. The original first_ex (e.g., a real send error) never escapes, even though the comment says we want to surface it. This regresses error observability—callers only see “Report schedule was modified…” instead of the actual failure. Please re-raise first_ex (or otherwise ensure the original exception propagates) while still logging the StaleDataError.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #35800:
URL: https://github.com/apache/superset/pull/35800
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2453038096
##########
superset/commands/report/execute.py:
##########
@@ -849,10 +878,14 @@ def next(self) -> None:
try:
self.send()
self.update_report_schedule_and_log(ReportState.SUCCESS)
+ except ReportScheduleUnexpectedError:
+ # Don't try to log again if logging itself failed
+ raise
Review Comment:
From codex
> when the fallback update_report_schedule_and_log hits the new StaleDataError path, the broad except Exception as ex is pre-empted and the caller never sees ex. We still want the StaleDataError handling, but after rolling back we should bubble up the original ex so schedule failures remain diagnosable.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2475478215
##########
superset/commands/report/execute.py:
##########
@@ -850,9 +890,21 @@ def next(self) -> None:
self.send()
self.update_report_schedule_and_log(ReportState.SUCCESS)
except Exception as ex: # pylint: disable=broad-except
- self.update_report_schedule_and_log(
- ReportState.ERROR, error_message=str(ex)
- )
+ try:
+ self.update_report_schedule_and_log(
+ ReportState.ERROR, error_message=str(ex)
+ )
+ except ReportScheduleUnexpectedError:
+ # Logging failed (likely StaleDataError), but we still want to
+ # raise the original error so the root cause remains visible
+ logger.warning(
+ "Failed to log error for report schedule %s due to database issue",
+ self._report_schedule.id,
+ exc_info=True,
+ )
+ # Re-raise the original exception, not the logging failure
+ raise ex from None
Review Comment:
The same raise ex from None pattern and will likewise strip the wrapped StaleDataError; preserving the cause here is important for debugging reports that are deleted mid-run.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #35800:
URL: https://github.com/apache/superset/pull/35800#issuecomment-3433326321
<details open>
<summary><strong>Interaction Diagram by <a href="https://bito.ai#sequence_diagram">Bito</a></strong></summary>
```mermaid
sequenceDiagram
participant SCHED as Scheduler Task
participant CMD as AsyncExecuteReportScheduleCommand
participant STATE as ReportNotTriggeredErrorState<br/>🔄 Updated | ●●● High
participant BASE as BaseReportState<br/>🔄 Updated | ●●● High
participant DB as Database Session
participant LOG as ReportExecutionLog
Note over STATE, BASE: Enhanced error handling<br/>for concurrent modifications
SCHED->>CMD: execute_async(task_id, schedule_id)
CMD->>STATE: next() - process report
STATE->>STATE: send() report/alert
STATE->>BASE: update_report_schedule_and_log()
BASE->>LOG: create ReportExecutionLog
BASE->>DB: session.add(log) & commit
DB-->>BASE: StaleDataError (concurrent mod)
BASE->>BASE: rollback & raise ReportScheduleUnexpectedError
BASE-->>STATE: propagate exception
STATE-->>SCHED: ReportScheduleUnexpectedError handled
```
Critical path: Scheduler Task->AsyncExecuteReportScheduleCommand->ReportNotTriggeredErrorState->BaseReportState->Database Session
> **Note:** The report execution logging now handles StaleDataError exceptions when concurrent processes modify or delete report schedules during execution. This prevents cascading failures by catching database concurrency issues and raising specific ReportScheduleUnexpectedError exceptions that the scheduler can handle appropriately.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2475481485
##########
superset/commands/report/execute.py:
##########
@@ -177,19 +177,34 @@ def create_log(self, error_message: Optional[str] = None) -> None:
"""
Creates a Report execution log, uses the current computed last_value for Alerts
"""
- log = ReportExecutionLog(
- scheduled_dttm=self._scheduled_dttm,
- start_dttm=self._start_dttm,
- end_dttm=datetime.utcnow(),
- value=self._report_schedule.last_value,
- value_row_json=self._report_schedule.last_value_row_json,
- state=self._report_schedule.last_state,
- error_message=error_message,
- report_schedule=self._report_schedule,
- uuid=self._execution_id,
- )
- db.session.add(log)
- db.session.commit() # pylint: disable=consider-using-transaction
+ from sqlalchemy.orm.exc import StaleDataError
+
+ try:
+ log = ReportExecutionLog(
+ scheduled_dttm=self._scheduled_dttm,
+ start_dttm=self._start_dttm,
+ end_dttm=datetime.utcnow(),
+ value=self._report_schedule.last_value,
+ value_row_json=self._report_schedule.last_value_row_json,
+ state=self._report_schedule.last_state,
+ error_message=error_message,
+ report_schedule=self._report_schedule,
+ uuid=self._execution_id,
+ )
+ db.session.add(log)
+ db.session.commit() # pylint: disable=consider-using-transaction
+ except StaleDataError as ex:
Review Comment:
The new StaleDataError handling isn’t covered by tests—could we add a scheduler test that mocks db.session.commit to raise StaleDataError and asserts we surface ReportScheduleUnexpectedError while leaving the original cause intact?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2483002903
##########
superset/commands/report/execute.py:
##########
@@ -752,14 +767,21 @@ def next(self) -> None:
return
self.send()
self.update_report_schedule_and_log(ReportState.SUCCESS)
+ except ReportScheduleUnexpectedError:
+ # Don't try to log again if logging itself failed
+ raise
except (SupersetErrorsException, Exception) as first_ex:
error_message = str(first_ex)
if isinstance(first_ex, SupersetErrorsException):
error_message = ";".join([error.message for error in first_ex.errors])
- self.update_report_schedule_and_log(
- ReportState.ERROR, error_message=error_message
- )
+ try:
Review Comment:
Thanks @sadpandajoe. Do you want to run codex again on these changes now?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #35800:
URL: https://github.com/apache/superset/pull/35800#issuecomment-3433297388
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): improve error handling for report schedule execution [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35800:
URL: https://github.com/apache/superset/pull/35800#discussion_r2475475819
##########
superset/commands/report/execute.py:
##########
@@ -757,9 +772,20 @@ def next(self) -> None:
if isinstance(first_ex, SupersetErrorsException):
error_message = ";".join([error.message for error in first_ex.errors])
- self.update_report_schedule_and_log(
- ReportState.ERROR, error_message=error_message
- )
+ try:
+ self.update_report_schedule_and_log(
+ ReportState.ERROR, error_message=error_message
+ )
+ except ReportScheduleUnexpectedError:
+ # Logging failed (likely StaleDataError), but we still want to
+ # raise the original error so the root cause remains visible
+ logger.warning(
+ "Failed to log error for report schedule %s due to database issue",
+ self._report_schedule.id,
+ exc_info=True,
+ )
+ # Re-raise the original exception, not the logging failure
+ raise first_ex from None
Review Comment:
re-raising first_ex with from None clears its __cause__, so when the original failure is a eportScheduleUnexpectedError (wrapping a StaleDataError) we lose the underlying concurrency stack trace; please re-raise without from None (or otherwise preserve the cause) so operators can still see the stale-write details.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org