dangdtr commented on code in PR #42474:
URL: https://github.com/apache/superset/pull/42474#discussion_r3656637682


##########
superset/connectors/sqla/models.py:
##########
@@ -169,6 +167,37 @@ class MetadataResult:
 ]
 
 
+def _get_query_context_column_names(slc: Slice) -> set[str] | None:
+    """Extract column names from a chart's serialized query context."""
+    if not slc.query_context:
+        return None
+
+    try:
+        query_context = json.loads(slc.query_context)
+    except json.JSONDecodeError as ex:
+        logger.error("Malformed json in slice's query context", exc_info=True)
+        logger.exception(ex)
+        return None
+
+    if not isinstance(query_context, dict):
+        return None
+
+    queries = query_context.get("queries")
+    if not isinstance(queries, list):
+        return None
+
+    column_names: set[str] = set()
+    for query in queries:
+        if not isinstance(query, dict):
+            continue
+        columns = query["columns"] if "columns" in query else 
query.get("groupby")
+        if not isinstance(columns, list):
+            continue
+        column_names.update(utils.get_column_name(column_) for column_ in 
columns)

Review Comment:
   Fixed in 5fbd67df98701c231c7f26dd1151d878c68ef08a. Invalid column entries 
that raise ValueError are treated as a malformed serialized query context, so 
data_for_slices falls back to form_data. Added regression coverage for both 
null and empty-dict entries.



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