bito-code-review[bot] commented on code in PR #37433:
URL: https://github.com/apache/superset/pull/37433#discussion_r2726306839
##########
superset/mcp_service/chart/chart_utils.py:
##########
@@ -105,14 +152,84 @@ def generate_explore_link(dataset_id: int | str,
form_data: Dict[str, Any]) -> s
)
+def is_column_truly_temporal(column_name: str, dataset_id: int | str | None)
-> bool:
+ """
+ Check if a column is truly temporal based on its SQL data type.
+
+ This is important because Superset may mark columns as is_dttm=True based
on
+ column name heuristics (e.g., "year", "month"), but if the actual SQL type
is
+ BIGINT or INTEGER, DATE_TRUNC will fail.
+
+ Args:
+ column_name: Name of the column to check
+ dataset_id: Dataset ID to look up column metadata
+
+ Returns:
+ True if the column has a real temporal SQL type, False otherwise
+ """
+ if not dataset_id:
+ return True # Default to temporal if we can't check (backward
compatible)
+
+ try:
+ from superset.daos.dataset import DatasetDAO
+
+ # Find dataset
+ if isinstance(dataset_id, int) or (
+ isinstance(dataset_id, str) and dataset_id.isdigit()
+ ):
+ dataset = DatasetDAO.find_by_id(int(dataset_id))
+ else:
+ dataset = DatasetDAO.find_by_id(dataset_id, id_column="uuid")
+
+ if not dataset:
+ return True # Default to temporal if dataset not found
+
+ # Find the column and check its actual type
+ column_lower = column_name.lower()
+ for col in dataset.columns:
+ if col.column_name.lower() == column_lower:
+ col_type = str(col.type).upper() if col.type else ""
+
+ # Extract base type (handle cases like "BIGINT(20)" ->
"BIGINT")
+ base_type = col_type.split("(")[0].strip()
+
+ # Check if it's a numeric non-temporal type
+ if base_type in NUMERIC_NON_TEMPORAL_TYPES:
+ logger.debug(
+ "Column '%s' has numeric type '%s', treating as
non-temporal",
+ column_name,
+ col_type,
+ )
+ return False
+
+ # Check if it's a truly temporal type
+ if base_type in TEMPORAL_SQL_TYPES:
+ return True
+
+ # For other types, trust the is_dttm flag
+ return getattr(col, "is_dttm", False)
+
+ return True # Default if column not found
+
+ except Exception as e:
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Avoid catching blind Exception</b></div>
<div id="fix">
Replace bare `Exception` catch with specific exception types (e.g.,
`AttributeError`, `ValueError`, `DatasetNotFound`).
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
except (AttributeError, ValueError, KeyError) as e:
````
</div>
</details>
</div>
<small><i>Code Review Run #f72ed3</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]