bito-code-review[bot] commented on code in PR #37538:
URL: https://github.com/apache/superset/pull/37538#discussion_r2739274953
##########
superset/daos/log.py:
##########
@@ -142,7 +142,7 @@ def get_recent_activity(
"item_title": item_title,
"time": datetime_to_epoch(log.dttm),
"time_delta_humanized": humanize.naturaltime(
- datetime.utcnow() - log.dttm
+ datetime.now(timezone.utc) - log.dttm
),
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Runtime TypeError in datetime subtraction</b></div>
<div id="fix">
This change introduces a TypeError at runtime because
datetime.now(timezone.utc) is timezone-aware, while log.dttm (from the Log
model default=datetime.utcnow) is naive. In Python 3.9+, subtracting aware and
naive datetimes raises an error. The model assumes UTC but uses naive
datetimes, so the current time should also be naive to match.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
"time_delta_humanized": humanize.naturaltime(
datetime.now(timezone.utc).replace(tzinfo=None) -
log.dttm
),
````
</div>
</details>
</div>
<small><i>Code Review Run #a2bfe3</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
##########
tests/unit_tests/dao/queries_test.py:
##########
@@ -69,7 +69,7 @@ def test_query_dao_get_queries_changed_after(session:
Session) -> None:
database = Database(database_name="my_database",
sqlalchemy_uri="sqlite://")
- now = datetime.utcnow()
+ now = datetime.now(timezone.utc)
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Datetime type mismatch risk</b></div>
<div id="fix">
The test now uses timezone-aware datetime for 'now', but the Query model's
changed_on defaults to naive datetime.utcnow(), and
QueryDAO.get_queries_changed_after creates naive last_updated_dt. This mismatch
can cause SQLAlchemy to fail or give incorrect results when comparing aware and
naive datetimes in filters, as SQLAlchemy may not handle mixed types reliably.
</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 datetime, timezone
@@ -51,1 +51,1 @@
- last_updated_dt = datetime.utcfromtimestamp(last_updated_ms / 1000)
+ last_updated_dt = datetime.fromtimestamp(last_updated_ms / 1000,
tz=timezone.utc)
```
</div>
</details>
</div>
<small><i>Code Review Run #a2bfe3</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]