You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/04/20 00:17:35 UTC

[superset] branch slack_files_upload_v2 created (now a4b106ee87)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch slack_files_upload_v2
in repository https://gitbox.apache.org/repos/asf/superset.git


      at a4b106ee87 chore(slack): use recommended method for file upload

This branch includes the following new commits:

     new a4b106ee87 chore(slack): use recommended method for file upload

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: chore(slack): use recommended method for file upload

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch slack_files_upload_v2
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a4b106ee87d926ca3c16ecaf5cc37050966a7848
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Apr 19 17:17:19 2023 -0700

    chore(slack): use recommended method for file upload
---
 superset/reports/notifications/slack.py           | 14 +++++---------
 superset/tasks/slack_util.py                      |  7 +++++--
 tests/integration_tests/reports/commands_tests.py |  7 +++++--
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/superset/reports/notifications/slack.py b/superset/reports/notifications/slack.py
index b89a700ef9..b74d63eecc 100644
--- a/superset/reports/notifications/slack.py
+++ b/superset/reports/notifications/slack.py
@@ -162,7 +162,6 @@ Error: %(text)s
         title = self._content.name
         channel = self._get_channel()
         body = self._get_body()
-        file_type = "csv" if self._content.csv else "png"
         try:
             token = app.config["SLACK_API_TOKEN"]
             if callable(token):
@@ -170,14 +169,11 @@ Error: %(text)s
             client = WebClient(token=token, proxy=app.config["SLACK_PROXY"])
             # files_upload returns SlackResponse as we run it in sync mode.
             if files:
-                for file in files:
-                    client.files_upload(
-                        channels=channel,
-                        file=file,
-                        initial_comment=body,
-                        title=title,
-                        filetype=file_type,
-                    )
+                client.files_upload_v2(
+                    file_uploads=[{"file": file, "title": title} for file in files],
+                    channels=channel,
+                    initial_comment=body,
+                )
             else:
                 client.chat_postMessage(channel=channel, text=body)
             logger.info("Report sent to slack")
diff --git a/superset/tasks/slack_util.py b/superset/tasks/slack_util.py
index 652fd89b6f..16035e3ac7 100644
--- a/superset/tasks/slack_util.py
+++ b/superset/tasks/slack_util.py
@@ -47,8 +47,11 @@ def deliver_slack_msg(
     if file:
         response = cast(
             SlackResponse,
-            client.files_upload(
-                channels=slack_channel, file=file, initial_comment=body, title=subject
+            client.files_upload_v2(
+                channels=slack_channel,
+                file=file,
+                initial_comment=body,
+                title=subject,
             ),
         )
         assert response["file"], str(response)  # the uploaded file
diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py
index cad6a75a5d..9feb2169a5 100644
--- a/tests/integration_tests/reports/commands_tests.py
+++ b/tests/integration_tests/reports/commands_tests.py
@@ -1123,7 +1123,7 @@ def test_email_dashboard_report_schedule_force_screenshot(
 @pytest.mark.usefixtures(
     "load_birth_names_dashboard_with_slices", "create_report_slack_chart"
 )
-@patch("superset.reports.notifications.slack.WebClient.files_upload")
+@patch("superset.reports.notifications.slack.WebClient.files_upload_v2")
 @patch("superset.utils.screenshots.ChartScreenshot.get_screenshot")
 def test_slack_chart_report_schedule(
     screenshot_mock,
@@ -1147,7 +1147,10 @@ def test_slack_chart_report_schedule(
             )
 
             assert file_upload_mock.call_args[1]["channels"] == notification_targets[0]
-            assert file_upload_mock.call_args[1]["file"] == SCREENSHOT_FILE
+            assert (
+                file_upload_mock.call_args[1]["file_uploads"][0]["file"]
+                == SCREENSHOT_FILE
+            )
 
             # Assert logs are correct
             assert_log(ReportState.SUCCESS)