rusackas commented on code in PR #41966:
URL: https://github.com/apache/superset/pull/41966#discussion_r3565519881
##########
superset/commands/report/execute.py:
##########
@@ -223,22 +223,47 @@ def update_report_schedule_slack_v2(self) -> None:
def create_log(self, error_message: Optional[str] = None) -> None:
"""
Creates a Report execution log, uses the current computed last_value
for Alerts
+
+ A single execution transitions through the WORKING state before
reaching a
+ terminal state (SUCCESS/ERROR/NOOP/GRACE). To avoid duplicated rows in
the
+ execution-log view (see issue #29857), the terminal result is written
onto
+ the WORKING "trigger" row created earlier in the same execution rather
than
+ inserting a second row. The WORKING row is only used as a placeholder
while
+ the execution is in flight (``find_last_entered_working_log`` relies
on it
+ for working-timeout detection), so promoting it in place keeps one row
per
+ execution ``uuid`` without losing that behavior. The intentional
+ error-notification marker row is a terminal-to-terminal transition, so
it is
+ still recorded as a distinct row.
"""
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,
+ # Reuse the in-flight WORKING trigger row for this execution, if
any,
+ # so a single execution surfaces as a single log entry.
+ log = (
+ db.session.query(ReportExecutionLog)
+ .filter(
+ ReportExecutionLog.uuid == self._execution_id,
+ ReportExecutionLog.state == ReportState.WORKING,
+ ReportExecutionLog.error_message.is_(None),
+ )
+ .first()
+ if self._report_schedule.last_state != ReportState.WORKING
+ else None
)
Review Comment:
log's type is fully inferred from the ReportExecutionLog(...) call right
above it, so mypy has what it needs without the annotation. Leaving it as-is.
##########
tests/integration_tests/reports/commands_tests.py:
##########
@@ -772,6 +778,45 @@ def test_email_chart_report_schedule(
assert_log(ReportState.SUCCESS)
[email protected](
+ "load_birth_names_dashboard_with_slices", "create_report_email_chart"
+)
+@patch("superset.reports.notifications.email.send_email_smtp")
+@patch("superset.utils.screenshots.ChartScreenshot.get_screenshot")
+def test_email_chart_report_schedule_single_log_per_execution(
+ screenshot_mock,
+ email_mock,
+ create_report_email_chart,
+):
Review Comment:
Same as the other test-function threads here, untyped params/return to match
the rest of this integration test file.
--
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]