codeant-ai-for-open-source[bot] commented on code in PR #41133: URL: https://github.com/apache/superset/pull/41133#discussion_r3545165490
########## superset/dashboards/excel_export/email.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Email rendering and delivery for dashboard Excel exports. + +Bodies use inline styles only (no external CSS, no logo) to match Superset's +existing report notification emails, and all user-controlled values (dashboard +title, chart names) are HTML-escaped to avoid injection. +""" + +from __future__ import annotations + +from datetime import datetime + +from flask import current_app +from flask_babel import gettext as __, ngettext +from markupsafe import escape + +from superset.utils.core import send_email_smtp + +_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" Review Comment: **Suggestion:** Add an explicit type annotation for this module-level constant to satisfy the type-hint requirement for relevant variables. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is a new module-level string constant without an explicit type annotation. The rule requires type hints on relevant variables that can be annotated, so this is a real violation. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1caabcc93fbb4b73a03c3c1b9b29c982&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1caabcc93fbb4b73a03c3c1b9b29c982&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/dashboards/excel_export/email.py **Line:** 35:35 **Comment:** *Custom Rule: Add an explicit type annotation for this module-level constant to satisfy the type-hint requirement for relevant variables. 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%2F41133&comment_hash=6351722bb95954f0cb92aa53891cbca7d8365ec8cfd303fe5da8d1f51a4275f4&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=6351722bb95954f0cb92aa53891cbca7d8365ec8cfd303fe5da8d1f51a4275f4&reaction=dislike'>👎</a> ########## superset/dashboards/excel_export/email.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Email rendering and delivery for dashboard Excel exports. + +Bodies use inline styles only (no external CSS, no logo) to match Superset's +existing report notification emails, and all user-controlled values (dashboard +title, chart names) are HTML-escaped to avoid injection. +""" + +from __future__ import annotations + +from datetime import datetime + +from flask import current_app +from flask_babel import gettext as __, ngettext +from markupsafe import escape + +from superset.utils.core import send_email_smtp + +_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" +_FOOTER_STYLE = "color:#888;font-size:12px;" +_BUTTON_STYLE = ( + "display:inline-block;padding:10px 16px;background:#20a7c9;color:#ffffff;" + "text-decoration:none;border-radius:4px;" +) + +# Reason keys under which the export task groups charts it could not export. +# The task classifies each omitted chart under one of these; the email renders a +# separate, labelled section per non-empty group with its own remediation text. +ERROR_NO_QUERY_CONTEXT = "no-query-context" Review Comment: **Suggestion:** Add an explicit type hint for this exported error-key constant so relevant variables are typed consistently. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This new module-level constant is a plain string and lacks an explicit type annotation. Under the stated rule, that is a genuine omission for a relevant variable. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=495e0dcd20e247988ea19658a863ff7d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=495e0dcd20e247988ea19658a863ff7d&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/dashboards/excel_export/email.py **Line:** 45:45 **Comment:** *Custom Rule: Add an explicit type hint for this exported error-key constant so relevant variables are typed consistently. 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%2F41133&comment_hash=1b9a3eb045054f8c8aed743fbf7fe5c5ca6eaa33f5206d3b7970fffc0e715bd1&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=1b9a3eb045054f8c8aed743fbf7fe5c5ca6eaa33f5206d3b7970fffc0e715bd1&reaction=dislike'>👎</a> ########## superset/dashboards/excel_export/layout.py: ########## @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Determine the order in which a dashboard's charts appear in its layout.""" + +from __future__ import annotations + +from typing import Any, TYPE_CHECKING + +if TYPE_CHECKING: + from superset.models.dashboard import Dashboard + from superset.models.slice import Slice + +CHART_TYPE = "CHART" +ROOT_ID = "ROOT_ID" + + +def _walk_chart_ids(position: dict[str, Any]) -> list[int]: + """ + Depth-first walk of a dashboard ``position_json`` returning chart ids in + visual (layout) order, including tab-nested charts. Each chart id appears + once (first occurrence wins); cycles are guarded against. + """ + if ROOT_ID not in position: + return [] + + ordered: list[int] = [] + seen_charts: set[int] = set() + visited_nodes: set[str] = set() + stack: list[str] = [ROOT_ID] + + while stack: + node_id = stack.pop() + if node_id in visited_nodes: + continue + visited_nodes.add(node_id) + + node = position.get(node_id) + if not isinstance(node, dict): + continue + + if node.get("type") == CHART_TYPE: + chart_id = node.get("meta", {}).get("chartId") + if isinstance(chart_id, int) and chart_id not in seen_charts: + seen_charts.add(chart_id) + ordered.append(chart_id) + + # Push children in reverse so they are popped in their declared order. + children = node.get("children", []) + for child_id in reversed(children): + stack.append(child_id) + + return ordered + + +def get_charts_in_layout_order(dashboard: Dashboard) -> list[Slice]: + """ + Return the dashboard's charts ordered by their position in the layout. + + Charts are visited depth-first over ``position_json`` (so tab-nested charts + are included in tab order), de-duplicated when the same chart is placed more + than once, and any chart that belongs to the dashboard but is absent from + the layout is appended at the end ordered by id. Layout entries that no + longer correspond to a dashboard chart are skipped. + + :param dashboard: The dashboard whose charts to order + :returns: The dashboard's :class:`Slice` objects in layout order + """ + slices_by_id: dict[int, Slice] = {slc.id: slc for slc in dashboard.slices} + + result: list[Slice] = [] + used: set[int] = set() + for chart_id in _walk_chart_ids(dashboard.position): + slc = slices_by_id.get(chart_id) + if slc is not None and chart_id not in used: + used.add(chart_id) + result.append(slc) + + orphans = sorted( + (slc for chart_id, slc in slices_by_id.items() if chart_id not in used), + key=lambda slc: slc.id, + ) Review Comment: **Suggestion:** Add a concrete type hint for this computed list before extending the result to satisfy explicit typing requirements. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The rule applies to relevant variables that can be annotated. `orphans` is a derived list of `Slice` objects with no explicit type annotation, so the suggestion identifies a genuine type-hint omission. </details> <details> <summary><b>Rule source 📖 </b></summary> .cursor/rules/dev-standard.mdc (line 28) </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=cf9a6ed6ab104a0e8ce692db9086e2ab&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=cf9a6ed6ab104a0e8ce692db9086e2ab&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/dashboards/excel_export/layout.py **Line:** 92:95 **Comment:** *Custom Rule: Add a concrete type hint for this computed list before extending the result to satisfy explicit typing requirements. 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%2F41133&comment_hash=b532de962b4cf1baf54ff8f0a729a2821c5094afc04c3b765dfd6205f13f4732&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=b532de962b4cf1baf54ff8f0a729a2821c5094afc04c3b765dfd6205f13f4732&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]
