bito-code-review[bot] commented on code in PR #36987:
URL: https://github.com/apache/superset/pull/36987#discussion_r2673876010
##########
superset-frontend/src/pages/AlertReportList/index.tsx:
##########
@@ -377,7 +392,21 @@ function AlertList({
original.owners.map((o: Owner) => o.id).includes(user.userId) ||
isUserAdmin(user);
+ const isRunning = original.lastState === AlertState.Working;
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Property name mismatch in running check</b></div>
<div id="fix">
The check for `isRunning` uses `original.lastState`, but the property is
`last_state` (as defined in `AlertObject`), causing the condition to always
evaluate to false and failing to disable the run now button when a report is
already running.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
const isRunning = original.last_state === AlertState.Working;
````
</div>
</details>
</div>
<small><i>Code Review Run #fc69a5</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/reports/api.py:
##########
@@ -460,6 +465,38 @@ def put(self, pk: int) -> Response:
)
return self.response_422(message=str(ex))
+ @expose("/<int:pk>/run_now", methods=("POST",))
+ @protect()
+ @safe
+ def run_now(self, pk) -> Response:
+ """
+ Run a report immediately, bypassing the schedule.
+ ---
+ post:
+ description: Run a report immediately
+ parameters:
+ - in: path
+ name: pk
+ schema:
+ type: integer
+ required: true
+ description: ReportSchedule primary key
+ responses:
+ 200:
+ description: Report triggered
+ 500:
+ description: Failed to run report
+ """
+ # Use a random UUID for the execution id
+ execution_id = str(uuid4())
+ # Use current time as scheduled_dttm
+ scheduled_dttm = datetime.utcnow()
+ try:
+ AsyncExecuteReportScheduleCommand(execution_id, pk,
scheduled_dttm).run()
+ return self.response(200, message="Report execution started")
+ except Exception as ex:
+ return self.response(500, message=f"Failed to run report: {ex}")
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Blind exception catch should be specific</b></div>
<div id="fix">
Replace the broad `except Exception` clause with specific exception types
(e.g., `ReportScheduleNotFoundError`, `SupersetException`) to improve error
handling and debugging.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
AsyncExecuteReportScheduleCommand(execution_id, pk,
scheduled_dttm).run()
return self.response(200, message="Report execution started")
except (ReportScheduleNotFoundError, ReportScheduleInvalidError,
SupersetException) as ex:
return self.response(500, message=f"Failed to run report: {ex}")
````
</div>
</details>
</div>
<small><i>Code Review Run #fc69a5</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset/reports/api.py:
##########
@@ -460,6 +465,38 @@ def put(self, pk: int) -> Response:
)
return self.response_422(message=str(ex))
+ @expose("/<int:pk>/run_now", methods=("POST",))
+ @protect()
+ @safe
+ def run_now(self, pk) -> Response:
+ """
+ Run a report immediately, bypassing the schedule.
+ ---
+ post:
+ description: Run a report immediately
+ parameters:
+ - in: path
+ name: pk
+ schema:
+ type: integer
+ required: true
+ description: ReportSchedule primary key
+ responses:
+ 200:
+ description: Report triggered
+ 500:
+ description: Failed to run report
+ """
+ # Use a random UUID for the execution id
+ execution_id = str(uuid4())
+ # Use current time as scheduled_dttm
+ scheduled_dttm = datetime.utcnow()
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Use of datetime.utcnow() is deprecated</b></div>
<div id="fix">
Replace `datetime.utcnow()` with `datetime.now(timezone.utc)` to use
timezone-aware datetime objects, as `utcnow()` is deprecated in Python 3.12+.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
from datetime import datetime
+from datetime import timezone
@@ -493,1 +494,1 @@
- scheduled_dttm = datetime.utcnow()
+ scheduled_dttm = datetime.now(timezone.utc)
```
</div>
</details>
</div>
<small><i>Code Review Run #fc69a5</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]