bito-code-review[bot] commented on code in PR #36034:
URL: https://github.com/apache/superset/pull/36034#discussion_r2500889596


##########
superset/utils/core.py:
##########
@@ -1618,7 +1618,9 @@ def get_column_name_from_metric(metric: Metric) -> str | 
None:
     if is_adhoc_metric(metric):
         metric = cast(AdhocMetric, metric)
         if metric["expressionType"] == AdhocMetricExpressionType.SIMPLE:
-            return cast(dict[str, Any], metric["column"])["column_name"]
+            column = metric["column"]

Review Comment:
   
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Add null check for metric column access</b></div>
   <div id="fix">
   
   The original code directly accesses metric["column"]["column_name"] without 
checking if column is None, which can cause a TypeError in production when the 
column field is missing. The change adds a null check by extracting column into 
a variable and verifying it exists before accessing its properties, preventing 
runtime errors and ensuring graceful handling of None values.
   </div>
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```
    -            return cast(dict[str, Any], metric["column"])["column_name"]
    +            column = metric["column"]
    +            if column:
    +                return column["column_name"]
   ```
   
   </div>
   </details>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run <a 
href=https://github.com/apache/superset/pull/36034#issuecomment-3499385240>#5bb146</a></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]

Reply via email to