codeant-ai-for-open-source[bot] commented on code in PR #44953:
URL: https://github.com/apache/superset/pull/44953#discussion_r4173991437


##########
superset/semantic_layers/models.py:
##########
@@ -376,7 +376,38 @@ def get_query_result(self, query_object: QueryObject) -> 
QueryResult:
                 result.df = query_object.exec_post_processing(result.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 an 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.
+                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

Review Comment:
   **Suggestion:** A custom operation can raise `KeyError` for an internal 
lookup, but this handler falsely reports that a requested column or level is 
missing.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Incorrect condition 
logic`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ffd62019c7fe4eb2a9aed6c33b267f78&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ffd62019c7fe4eb2a9aed6c33b267f78&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/semantic_layers/models.py
   **Line:** 386:397
   **Comment:**
        *Incorrect Condition Logic: A custom operation can raise `KeyError` for 
an internal lookup, but this handler falsely reports that a requested column or 
level is missing.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44953&comment_hash=0dae37dd382bea573a32cf4d08333e21fd4ffe9b744ba7fca4426a61837cb8f3&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44953&comment_hash=0dae37dd382bea573a32cf4d08333e21fd4ffe9b744ba7fca4426a61837cb8f3&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/semantic_layers/models.py:
##########
@@ -376,7 +376,38 @@ def get_query_result(self, query_object: QueryObject) -> 
QueryResult:
                 result.df = query_object.exec_post_processing(result.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 an 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.
+                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:
+                # These types are broad enough to also cover a genuine fault in
+                # an operation, and the caller turns this into a message on the
+                # response without logging it, so keep the traceback.
+                logger.warning(
+                    "Post-processing failed and was reported as a bad request",
+                    exc_info=True,
+                )
                 raise QueryObjectValidationError(str(ex)) from ex

Review Comment:
   **Suggestion:** Custom operations are supported here, but their internal 
`TypeError`, `ValueError`, or `AttributeError` failures become client 400 
errors instead of server failures.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ece876d06b214d13821d1ffd5263ce6a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ece876d06b214d13821d1ffd5263ce6a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/semantic_layers/models.py
   **Line:** 398:411
   **Comment:**
        *Api Mismatch: Custom operations are supported here, but their internal 
`TypeError`, `ValueError`, or `AttributeError` failures become client 400 
errors instead of server failures.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44953&comment_hash=04ade3005ffee3d909797e20955947ce9dc3779c197c90cf1ac0fb706937267b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44953&comment_hash=04ade3005ffee3d909797e20955947ce9dc3779c197c90cf1ac0fb706937267b&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
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