apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
60.51k stars 13.07k forks source link

Slack Notification - deprecated API #29480

Open PuszekSE opened 4 days ago

PuszekSE commented 4 days ago

Bug description

When attempting to send the notification it seems to be failing due to Slack API deprecation:

[2024-07-03 04:13:16,531: WARNING/ForkPoolWorker-16] SupersetError(message="The request to the Slack API failed. (url: https://www.slack.com/api/files.upload)\nThe server responded with: {'ok': False, 'error': 'method_deprecated'}", error_type=<SupersetErrorType.REPORT_NOTIFICATION_ERROR: 'REPORT_NOTIFICATION_ERROR'>, level=<ErrorLevel.WARNING: 'warning'>, extra=None)
header_data in notifications for alerts and reports {'notification_type': 'Alert', 'notification_source': <ReportSourceFormat.DASHBOARD: 'dashboard'>, 'notification_format': 'PNG', 'chart_id': None, 'dashboard_id': 1, 'owners': [...]}, taskid, 52c32a04-bce5-45a9-9add-511c252908fa

[2024-07-03 04:13:16,579: INFO/ForkPoolWorker-16] header_data in notifications for alerts and reports {'notification_type': 'Alert', 'notification_source': <ReportSourceFormat.DASHBOARD: 'dashboard'>, 'notification_format': 'PNG', 'chart_id': None, 'dashboard_id': 1, 'owners': [...]}, taskid, 52c32a04-bce5-45a9-9add-511c252908fa
SupersetError(message='[Errno 111] Connection refused', error_type=<SupersetErrorType.REPORT_NOTIFICATION_ERROR: 'REPORT_NOTIFICATION_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra=None)

[2024-07-03 04:13:16,581: WARNING/ForkPoolWorker-16] SupersetError(message='[Errno 111] Connection refused', error_type=<SupersetErrorType.REPORT_NOTIFICATION_ERROR: 'REPORT_NOTIFICATION_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra=None)
A downstream warning occurred while generating a report: 52c32a04-bce5-45a9-9add-511c252908fa. [SupersetError(message="The request to the Slack API failed. (url: https://www.slack.com/api/files.upload)\nThe server responded with: {'ok': False, 'error': 'method_deprecated'}", error_type=<SupersetErrorType.REPORT_NOTIFICATION_ERROR: 'REPORT_NOTIFICATION_ERROR'>, level=<ErrorLevel.WARNING: 'warning'>, extra=None)]
Traceback (most recent call last):
  File "/app/superset/tasks/scheduler.py", line 90, in execute
    AsyncExecuteReportScheduleCommand(
  File "/app/superset/commands/report/execute.py", line 721, in run
    raise ex
  File "/app/superset/commands/report/execute.py", line 717, in run
    ReportScheduleStateMachine(
  File "/app/superset/commands/report/execute.py", line 678, in run
    state_cls(
  File "/app/superset/commands/report/execute.py", line 582, in next
    raise first_ex
  File "/app/superset/commands/report/execute.py", line 551, in next
    self.send()
  File "/app/superset/commands/report/execute.py", line 451, in send
    self._send(notification_content, self._report_schedule.recipients)
  File "/app/superset/commands/report/execute.py", line 442, in _send
    raise ReportScheduleClientErrorsException(errors=notification_errors)
superset.commands.report.exceptions.ReportScheduleClientErrorsException: [SupersetError(message="The request to the Slack API failed. (url: https://www.slack.com/api/files.upload)\nThe server responded with: {'ok': False, 'error': 'method_deprecated'}", error_type=<SupersetErrorType.REPORT_NOTIFICATION_ERROR: 'REPORT_NOTIFICATION_ERROR'>, level=<ErrorLevel.WARNING: 'warning'>, extra=None)]

How to reproduce the bug

  1. Setup notification via Slack using SLACK_TOKEN_API
  2. Send dashboard as a notification to the channel

Screenshots/recordings

image image image

Superset version

master / latest-dev

Python version

Not applicable

Node version

Not applicable

Browser

Not applicable

Additional context

It's k8s based deployment based on 4.0.2rc-dev image if that matters anyhow.

Checklist

dosubot[bot] commented 4 days ago

Hey there, @PuszekSE! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to resolve this issue.

To resolve the issue of sending notifications via Slack failing due to a deprecated Slack API method in your Superset deployment, you should update your Slack app to use the new API methods. Specifically, you should replace the deprecated files_upload method with the new files_upload_v2 method.

Here is the relevant part of the code that shows the use of the new method:

# files_upload returns SlackResponse as we run it in sync mode.
for channel in channels:
    if len(files) > 0:
        for file in files:
            client.files_upload_v2(
                channel=channel,
                file=file,
                initial_comment=body,
                title=title,
            )
    else:
        client.chat_postMessage(channel=channel, text=body)

Ensure that your Slack app has the necessary permissions and scopes to use the new API methods. If the new method fails, the code falls back to the deprecated method, but this should be avoided by updating your Slack app configuration [1].

To continue talking to Dosu, mention @dosu.

VedantBopardikar commented 1 day ago

Where can i find this code to replace it in superset files?

@dosu

rusackas commented 21 hours ago

I think this has recently been patched on master. @eschutho would know the most here, I think.

PuszekSE commented 1 hour ago

I've checked this on 4.0.2-dev, 1-2 days after its release (although that isn't an option present on the version dropdown list).