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


##########
superset/models/helpers.py:
##########
@@ -2683,7 +2683,45 @@ def get_query_result(self, query_object: QueryObject) -> 
QueryResult:
                 df = query_object.exec_post_processing(df)
             except InvalidPostProcessingError as ex:
                 raise QueryObjectValidationError(ex.message) from ex
-            except (TypeError, pd.errors.DataError) as ex:
+            # A post-processing operation is driven entirely by the request's
+            # `options` dict, which `ChartDataPostProcessingOperationSchema`
+            # accepts as an untyped `fields.Dict`. A malformed option therefore
+            # reaches pandas and surfaces as whatever pandas raises, so these
+            # are bad-request failures, not server faults. ImportError is
+            # deliberately excluded: a missing optional dependency (scipy, for
+            # a `rolling` win_type) is a deployment matter, not a bad request.
+            except KeyError as ex:
+                # Every KeyError a built-in operation raises names a column or
+                # MultiIndex level the options asked for and the result does
+                # not have. `str(KeyError)` is only the repr'd key, which alone
+                # reads as a bare quoted string. An operation registered
+                # through EXTRA_PANDAS_POSTPROCESSING_OPS could raise KeyError
+                # from its own internals, where that wording would be a guess,
+                # which is the other reason to keep the traceback.
+                logger.warning(
+                    "Post-processing failed and was reported as a bad request",
+                    exc_info=True,
+                )
+                raise QueryObjectValidationError(
+                    _(
+                        "Post-processing references a column or level that is "
+                        "not in the query result: %(name)s",
+                        name=ex.args[0] if ex.args else ex,
+                    )
+                ) from ex
+            except (
+                TypeError,
+                ValueError,
+                AttributeError,
+                pd.errors.DataError,
+            ) as ex:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Broad except masks server faults</b></div>
   <div id="fix">
   
   The broad `except (TypeError, ValueError, AttributeError, 
pd.errors.DataError)` converts any genuine fault inside a post-processing 
operation into a 400 bad-request via `QueryObjectValidationError` 
(charts/data/api.py:227). A real bug in an operation (e.g. an `AttributeError` 
from a typo) is then hidden from the user as a client error instead of a 500. 
The comment acknowledges this tradeoff; consider narrowing the catch or 
re-raising genuine faults so server faults stay visible.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #96245a</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