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


##########
superset/charts/data/api.py:
##########
@@ -578,15 +612,20 @@ def _get_data_response(
     ) -> Response:
         """Get data response and optionally log is_cached information."""
         try:
-            result = command.run(force_cached=force_cached)
+            with chart_timing_phase("query"):
+                result = command.execute(
+                    ChartDataExecutionOptions(force_cached=force_cached)
+                )
         except ChartDataCacheLoadError as exc:
             return self.response_422(message=exc.message)
         except ChartDataQueryFailedError as exc:
             return self.response_400(message=exc.message)
 
             # Log is_cached if extra payload callback is provided
-        if add_extra_log_payload and result and "queries" in result:
-            is_cached_values = [query.get("is_cached") for query in 
result["queries"]]
+        if add_extra_log_payload:
+            is_cached_values = [
+                query.payload.get("is_cached") for query in result.queries
+            ]
             add_extra_log_payload(is_cached=is_cached_values)
 

Review Comment:
   **Suggestion:** The sync path now always logs `is_cached` as a list, but the 
async cache-hit path still logs a scalar for single-query responses. This 
breaks the existing event payload contract and can cause downstream log 
consumers/analytics that expect a boolean for single-query requests to 
mis-parse or fail. Reuse the existing single-vs-multi shaping logic (or 
`_log_is_cached`) so both paths emit the same type. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Event log field is_cached type inconsistent across paths.
   - ⚠️ Downstream analytics expecting boolean may break on lists.
   - ⚠️ Harder to process chart cache status uniformly from logs.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. The chart data endpoints `get_data`, `data`, and `data_from_cache` in
   `superset/charts/data/api.py:89-185` are decorated with
   `event_logger.log_this_with_context(..., allow_extra_payload=True)`, which, 
via
   `superset/utils/log.py:15-23`, passes an `add_extra_log_payload` callback 
into these view
   functions.
   
   2. For async cache-hit responses, `ChartDataRestApi._run_async` in
   `superset/charts/data/api.py:186-207` calls `self._log_is_cached(result,
   add_extra_log_payload)` when `result` is not `None`. `_log_is_cached` at
   `superset/charts/data/api.py:62-81` builds `is_cached_values =
   [query.payload.get("is_cached") for query in result.queries]` and, if there 
is a single
   query, calls `add_extra_log_payload(is_cached=is_cached_values[0])`, 
emitting a scalar
   boolean for `is_cached` on single-query results and a list for multi-query 
results as
   documented in its docstring.
   
   3. For synchronous chart data responses (e.g., when `use_async` is `False` 
in `get_data`
   or `data`, or when `data_from_cache` calls `_get_data_response(command, 
True)`),
   `ChartDataRestApi._get_data_response` in 
`superset/charts/data/api.py:83-120` executes the
   query and then, in the new lines `626-630`, logs cache status by 
unconditionally building
   `is_cached_values = [query.payload.get("is_cached") for query in 
result.queries]` and
   calling `add_extra_log_payload(is_cached=is_cached_values)`, even when there 
is only one
   query, thus emitting a list instead of the scalar boolean used by 
`_log_is_cached`.
   
   4. As a result, the same `is_cached` field in the event logger payload is a 
boolean for
   single-query async cache hits (via `_run_async` → `_log_is_cached`) but a 
single-element
   list for single-query synchronous responses (via `_get_data_response`), 
breaking the
   established event payload contract described in `_log_is_cached` and causing 
downstream
   log consumers or analytics that expect a boolean for single-query requests 
to mis-parse or
   fail when they encounter the list type from the sync path.
   ```
   </details>
   
   [![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=712bfc704ff9405aa31062c07af6f478&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=712bfc704ff9405aa31062c07af6f478&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/charts/data/api.py
   **Line:** 626:630
   **Comment:**
        *Api Mismatch: The sync path now always logs `is_cached` as a list, but 
the async cache-hit path still logs a scalar for single-query responses. This 
breaks the existing event payload contract and can cause downstream log 
consumers/analytics that expect a boolean for single-query requests to 
mis-parse or fail. Reuse the existing single-vs-multi shaping logic (or 
`_log_is_cached`) so both paths emit the same type.
   
   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%2F37516&comment_hash=f22b8416f540a16bc489703a6616287037033922d37a35bc50f7b0555845f22e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37516&comment_hash=f22b8416f540a16bc489703a6616287037033922d37a35bc50f7b0555845f22e&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