codeant-ai-for-open-source[bot] commented on code in PR #41133:
URL: https://github.com/apache/superset/pull/41133#discussion_r3509694551
##########
superset/config.py:
##########
@@ -1369,6 +1369,23 @@ def sync_theme_logo_href(
# note: index option should not be overridden
EXCEL_EXPORT: dict[str, Any] = {}
+# ---------------------------------------------------
+# Dashboard "Export Data to Excel" (async, S3-backed)
+# ---------------------------------------------------
+# Destination S3 bucket for generated dashboard .xlsx exports. The feature is
+# disabled until this is set: the export endpoint returns 501 when it is None.
+EXCEL_EXPORT_S3_BUCKET: str | None = None
+# Key prefix for export objects: {prefix}{dashboard_id}/{job_id}.xlsx
+EXCEL_EXPORT_S3_KEY_PREFIX = "dashboard-exports/"
+# Lifetime (seconds) of the pre-signed download URL emailed to the user (24h).
+# Note: AWS S3 caps pre-signed URL lifetime at 7 days (604800 seconds); larger
+# values are rejected by S3, so keep this at or below that when using AWS.
+EXCEL_EXPORT_LINK_TTL_SECONDS = 86400
Review Comment:
**Suggestion:** Add an explicit type hint to this new numeric configuration
variable so the newly introduced setting is fully typed. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
This new configuration variable is a plain integer setting and is fully
annotatable, but it lacks an explicit type hint. That is a real violation of
the Python type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a8bf7a849c9542b98448cbef126a5b97&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=a8bf7a849c9542b98448cbef126a5b97&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/config.py
**Line:** 1380:1383
**Comment:**
*Custom Rule: Add an explicit type hint to this new numeric
configuration variable so the newly introduced setting is fully typed.
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=2957618e0f0dbea94531ab7bef49f9241afedf1a7928c3266ff670e944a7bb8b&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=2957618e0f0dbea94531ab7bef49f9241afedf1a7928c3266ff670e944a7bb8b&reaction=dislike'>π</a>
##########
superset/config.py:
##########
@@ -1369,6 +1369,23 @@ def sync_theme_logo_href(
# note: index option should not be overridden
EXCEL_EXPORT: dict[str, Any] = {}
+# ---------------------------------------------------
+# Dashboard "Export Data to Excel" (async, S3-backed)
+# ---------------------------------------------------
+# Destination S3 bucket for generated dashboard .xlsx exports. The feature is
+# disabled until this is set: the export endpoint returns 501 when it is None.
+EXCEL_EXPORT_S3_BUCKET: str | None = None
+# Key prefix for export objects: {prefix}{dashboard_id}/{job_id}.xlsx
+EXCEL_EXPORT_S3_KEY_PREFIX = "dashboard-exports/"
Review Comment:
**Suggestion:** Add an explicit type hint to this new configuration variable
to comply with the type-annotation rule for annotatable variables. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
This is new Python configuration code in a .py file, and the variable is a
clear annotatable string setting. It currently omits an explicit type hint, so
it matches the type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=bcd7656dbfe4404bb15b86cf6c79796a&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=bcd7656dbfe4404bb15b86cf6c79796a&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/config.py
**Line:** 1378:1379
**Comment:**
*Custom Rule: Add an explicit type hint to this new configuration
variable to comply with the type-annotation rule for annotatable 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=f00d4e311a5c08d2d97b1370257a1fc8693d77caaea66dcb46d58660497dc6a2&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=f00d4e311a5c08d2d97b1370257a1fc8693d77caaea66dcb46d58660497dc6a2&reaction=dislike'>π</a>
##########
superset/utils/s3.py:
##########
@@ -0,0 +1,76 @@
+# 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.
+"""
+Minimal S3 helpers for uploading export artifacts and minting pre-signed URLs.
+
+Credentials and region come from the standard boto3 resolution chain (env vars,
+shared config, instance role). Operators can override client construction via
+the ``EXCEL_EXPORT_S3_CLIENT_KWARGS`` config (e.g. ``region_name`` or an
+``endpoint_url`` for S3-compatible stores such as MinIO/LocalStack).
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any
+
+from flask import current_app
+
+logger = logging.getLogger(__name__)
Review Comment:
**Suggestion:** Add an explicit type annotation to `logger` to satisfy the
type-hint requirement for relevant module-level variables. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The new Python module defines a module-level variable without an explicit
type hint. Since `logger` is a relevant variable that can be annotated, this
matches the type-hint rule for new or modified Python code.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=26d99b0ca3a348c3a232bf7c3220107a&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=26d99b0ca3a348c3a232bf7c3220107a&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/utils/s3.py
**Line:** 33:33
**Comment:**
*Custom Rule: Add an explicit type annotation to `logger` to satisfy
the type-hint requirement for relevant module-level 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=8070f7ac2f2cee71246e246df51eb08c5ab7844e33a97ad457c8524a8da2ab85&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=8070f7ac2f2cee71246e246df51eb08c5ab7844e33a97ad457c8524a8da2ab85&reaction=dislike'>π</a>
##########
tests/integration_tests/dashboards/api_tests.py:
##########
@@ -3279,6 +3280,91 @@ def _base_filter(query):
response_roles = [result["text"] for result in response["result"]]
assert response_roles == ["Alpha"]
+ def test_export_xlsx_501_when_bucket_unset(self):
+ """Dashboard API: export_xlsx returns 501 when the S3 bucket is
unset."""
+ admin = self.get_user("admin")
+ dashboard = self.insert_dashboard("xlsx-501", None, [admin.id])
+ self.login(ADMIN_USERNAME)
+ try:
+ rv =
self.client.post(f"api/v1/dashboard/{dashboard.id}/export_xlsx/")
+ assert rv.status_code == 501
+ finally:
+ db.session.delete(dashboard)
+ db.session.commit()
+
+ @patch("superset.dashboards.api.export_dashboard_excel")
+ def test_export_xlsx_404_for_missing_dashboard(self, mock_task):
+ """Dashboard API: export_xlsx returns 404 for an unknown dashboard."""
+ self.login(ADMIN_USERNAME)
+ with patch.dict(
+ "flask.current_app.config",
+ {"EXCEL_EXPORT_S3_BUCKET": "exports"},
+ ):
+ rv = self.client.post("api/v1/dashboard/99999999/export_xlsx/")
+ assert rv.status_code == 404
+ mock_task.apply_async.assert_not_called()
+
+ @patch("superset.dashboards.api.export_dashboard_excel")
+ def test_export_xlsx_400_for_empty_dashboard(self, mock_task):
+ """Dashboard API: export_xlsx returns 400 for a dashboard with no
charts."""
+ admin = self.get_user("admin")
+ dashboard = self.insert_dashboard("xlsx-empty", None, [admin.id])
+ self.login(ADMIN_USERNAME)
+ try:
+ with patch.dict(
+ "flask.current_app.config",
+ {"EXCEL_EXPORT_S3_BUCKET": "exports"},
+ ):
+ rv =
self.client.post(f"api/v1/dashboard/{dashboard.id}/export_xlsx/")
+ assert rv.status_code == 400
+ mock_task.apply_async.assert_not_called()
+ finally:
+ db.session.delete(dashboard)
+ db.session.commit()
+
+ @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
+ @patch("superset.dashboards.api.export_dashboard_excel")
Review Comment:
**Suggestion:** Annotate this methodβs argument and return type to satisfy
the type-hint requirement for new code. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
This newly added test method lacks annotations on `mock_task` and does not
declare a return type, so it violates the Python type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ed1a819bb78d4ab5b1ed9aabc843d434&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=ed1a819bb78d4ab5b1ed9aabc843d434&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:** tests/integration_tests/dashboards/api_tests.py
**Line:** 3326:3326
**Comment:**
*Custom Rule: Annotate this methodβs argument and return type to
satisfy the type-hint requirement for new code.
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=8c02e859dab8bf32648e62c8a69151d62a8bd398bab93506a8fa0fe3c0b8b822&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=8c02e859dab8bf32648e62c8a69151d62a8bd398bab93506a8fa0fe3c0b8b822&reaction=dislike'>π</a>
##########
tests/unit_tests/tasks/test_export_dashboard_excel.py:
##########
@@ -0,0 +1,212 @@
+# 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.
+from __future__ import annotations
+
+import glob
+import os
+import tempfile
+from collections.abc import Iterator
+from contextlib import ExitStack
+from typing import Any
+from unittest import mock
+
+import pytest
+from celery.exceptions import SoftTimeLimitExceeded
+
+from superset.utils import json
+
+MODULE = "superset.tasks.export_dashboard_excel"
+
+
+def _chart(chart_id: int, name: str, has_context: bool = True) ->
mock.MagicMock:
+ chart = mock.MagicMock()
+ chart.id = chart_id
+ chart.slice_name = name
+ chart.query_context = json.dumps({"queries": [{}]}) if has_context else
None
+ return chart
+
+
[email protected]
+def mocks() -> Iterator[dict[str, Any]]:
+ """Patch every external dependency of the task; keep the real xlsx
writer."""
+ with ExitStack() as stack:
+ # Use explicit MagicMock instances: patch() auto-creates async-flavored
+ # mocks for these targets (their real objects expose async members),
which
+ # would make calls like security_manager.get_user_by_id() return
coroutines.
+ patched = {
+ name: stack.enter_context(
+ mock.patch(f"{MODULE}.{name}", new=mock.MagicMock())
+ )
+ for name in (
+ "security_manager",
+ "db",
+ "get_charts_in_layout_order",
+ "get_dashboard_filter_context",
+ "ChartDataQueryContextSchema",
+ "ChartDataCommand",
+ "s3",
+ "email",
+ )
+ }
+ user = mock.MagicMock()
+ user.email = "[email protected]"
+ patched["security_manager"].get_user_by_id.return_value = user
+
+ dashboard = mock.MagicMock()
+ dashboard.id = 1
+ dashboard.dashboard_title = "Sales"
+ patched[
+ "db"
+
].session.query.return_value.filter_by.return_value.one_or_none.return_value =
( # noqa: E501
+ dashboard
+ )
Review Comment:
**Suggestion:** Add a type annotation to the mocked dashboard variable to
comply with the rule requiring hints on relevant variables. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The local variable `dashboard` is introduced without a type annotation in
new Python code. Since it is a relevant object in the test fixture and can be
annotated, it violates the type-hint requirement.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d435a332e6ee401ca6012be2ef6c0da8&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=d435a332e6ee401ca6012be2ef6c0da8&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:** tests/unit_tests/tasks/test_export_dashboard_excel.py
**Line:** 69:76
**Comment:**
*Custom Rule: Add a type annotation to the mocked dashboard variable to
comply with the rule requiring hints on 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=bbd771e763c6e27c8018b9d8149c0acac676754858c3d7116e89c6827234a925&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=bbd771e763c6e27c8018b9d8149c0acac676754858c3d7116e89c6827234a925&reaction=dislike'>π</a>
##########
tests/unit_tests/tasks/test_export_dashboard_excel.py:
##########
@@ -0,0 +1,212 @@
+# 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.
+from __future__ import annotations
+
+import glob
+import os
+import tempfile
+from collections.abc import Iterator
+from contextlib import ExitStack
+from typing import Any
+from unittest import mock
+
+import pytest
+from celery.exceptions import SoftTimeLimitExceeded
+
+from superset.utils import json
+
+MODULE = "superset.tasks.export_dashboard_excel"
+
+
+def _chart(chart_id: int, name: str, has_context: bool = True) ->
mock.MagicMock:
+ chart = mock.MagicMock()
+ chart.id = chart_id
+ chart.slice_name = name
+ chart.query_context = json.dumps({"queries": [{}]}) if has_context else
None
+ return chart
+
+
[email protected]
+def mocks() -> Iterator[dict[str, Any]]:
+ """Patch every external dependency of the task; keep the real xlsx
writer."""
+ with ExitStack() as stack:
+ # Use explicit MagicMock instances: patch() auto-creates async-flavored
+ # mocks for these targets (their real objects expose async members),
which
+ # would make calls like security_manager.get_user_by_id() return
coroutines.
+ patched = {
+ name: stack.enter_context(
+ mock.patch(f"{MODULE}.{name}", new=mock.MagicMock())
+ )
+ for name in (
+ "security_manager",
+ "db",
+ "get_charts_in_layout_order",
+ "get_dashboard_filter_context",
+ "ChartDataQueryContextSchema",
+ "ChartDataCommand",
+ "s3",
+ "email",
+ )
+ }
+ user = mock.MagicMock()
+ user.email = "[email protected]"
+ patched["security_manager"].get_user_by_id.return_value = user
Review Comment:
**Suggestion:** Add a type annotation to the mocked user variable so this
relevant local value is explicitly typed. [custom_rule]
**Severity Level:** Minor β οΈ
<details>
<summary><b>Why it matters? π€ </b></summary>
The local variable `user` is assigned in new Python code without a type
hint, and it is a relevant fixture value that can be annotated. This is a real
omission under the type-hint rule.
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7b5d1fb7349f4e88925ebb220243b32f&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=7b5d1fb7349f4e88925ebb220243b32f&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:** tests/unit_tests/tasks/test_export_dashboard_excel.py
**Line:** 65:67
**Comment:**
*Custom Rule: Add a type annotation to the mocked user variable so this
relevant local value is explicitly typed.
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=9bf42b696461ca9bc5470bd1e2b5536f3a60c3eb06c14a0c3cdb49cba212a727&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=9bf42b696461ca9bc5470bd1e2b5536f3a60c3eb06c14a0c3cdb49cba212a727&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]