Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack Notification - deprecated API #29480

Closed
3 tasks done
PuszekSE opened this issue Jul 4, 2024 · 12 comments
Closed
3 tasks done

Slack Notification - deprecated API #29480

PuszekSE opened this issue Jul 4, 2024 · 12 comments
Assignees
Labels
alert-reports Namespace | Anything related to the Alert & Reports feature

Comments

@PuszekSE
Copy link

PuszekSE commented Jul 4, 2024

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

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@dosubot dosubot bot added the alert-reports Namespace | Anything related to the Alert & Reports feature label Jul 4, 2024
Copy link

dosubot bot commented Jul 4, 2024

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

VedantBopardikar commented Jul 6, 2024

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

@dosu

@rusackas
Copy link
Member

rusackas commented Jul 7, 2024

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

@PuszekSE
Copy link
Author

PuszekSE commented Jul 8, 2024

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

@VedantBopardikar
Copy link

changing the function in superset/reports/notifications/slack.py. from files_upload to files_upload_v2 worked for me. Also the recipients in superset for slack should be channel IDs and not usernames.

@PuszekSE
Copy link
Author

#29264
#29264

I believe those were related PRs

@eschutho
Copy link
Member

Correct, the above two prs will fix this issue. There's one outstanding issue to be merged to fix the backend runtime migrations: #29721

@Chethanibms
Copy link

Chethanibms commented Nov 29, 2024

@eschutho With reference to the link #29480 (comment)
where do we need to change the slack files_upload_v2 in my helm chart

Copy link

dosubot bot commented Nov 29, 2024

The Slack notification code in the Superset codebase is located at superset/reports/notifications/slack.py [1].

To continue talking to Dosu, mention @dosu.

@Chethanibms
Copy link

@dosu getting error

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

where do i need to change the files_upload_v2 in my helm chart

@dosubot dosubot bot mentioned this issue Nov 29, 2024
3 tasks
@eschutho
Copy link
Member

eschutho commented Jan 7, 2025

If you are running Superset 4.1 or later you will be using the Slack v2 api if your Slack app has the correct scopes. Your logs will say which scopes you need to add if they are missing. You will also need to set this flag to true: ALERT_REPORT_SLACK_V2

Copy link

dosubot bot commented Jan 7, 2025

To resolve the error related to the deprecated Slack API method, you need to update the Superset codebase, not the Helm chart itself. Specifically, you should modify the superset/reports/notifications/slack.py file to replace the deprecated files_upload method with the files_upload_v2 method.

Here's a brief guide on how to do this:

  1. Locate the File: Access the superset/reports/notifications/slack.py file in your Superset deployment.

  2. Modify the Code: Replace the usage of files_upload with files_upload_v2. Here's the code snippet you need to update:

    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)
  3. Deploy the Changes: After making the changes, you need to redeploy your Superset application. If you're using a Helm chart, this typically involves building a new Docker image with your changes and updating your Helm deployment to use this new image.

  4. Ensure Permissions: Make sure your Slack app has the necessary permissions and scopes to use the files_upload_v2 method.

This change should resolve the error you're encountering with the deprecated Slack API method.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alert-reports Namespace | Anything related to the Alert & Reports feature
Projects
None yet
Development

No branches or pull requests

5 participants