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


##########
superset/db_engine_specs/elasticsearch.py:
##########
@@ -75,19 +82,19 @@ def _fetch_page_via_cursor(
         r"\s+LIMIT\s+\d+\s*$", "", sanitized_sql, flags=re.IGNORECASE
     )
 
-    # The raw transport does not auto-set Content-Type the way the Python
-    # DB-API driver does; ES rejects POSTs without a JSON content type.
-    json_headers = {"Content-Type": "application/json"}
+    request_kwargs: dict[str, Any] = {"headers": headers} if headers else {}
     with database.get_raw_connection() as conn:
         transport = conn.es.transport
         response = transport.perform_request(
             "POST",
             sql_path,
-            headers=json_headers,
             body={"query": sanitized_sql, "fetch_size": page_size},
+            **request_kwargs,
         )
-        columns = [col["name"] for col in response.get("columns", [])]
-        rows = response.get("rows", [])
+        columns = [
+            col.get("alias") or col["name"] for col in 
response.get(columns_key, [])
+        ]

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Unguarded column name access</b></div>
   <div id="fix">
   
   `col.get("alias") or col["name"]` mixes a guarded and an unguarded access: a 
column entry in the `columns_key`/`schema` payload lacking `name` raises 
KeyError, while the `alias` lookup tolerates absence. Repo test fixtures always 
include `name`, but the payload comes from the external 
Elasticsearch/OpenSearch service. Prefer `col.get("name")` so both keys are 
handled consistently.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #a5c03a</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