https://prefect.io logo
Title
k

kiran

01/31/2023, 5:06 PM
Hi y’all. Did something change with the Slack notifications? I’m getting these:
/my_path/.venv/lib/python3.10/site-packages/prefect/utilities/dispatch.py:162: UserWarning: Type 'SlackWebhook' at /my_path/.venv/lib/python3.10/site-packages/prefect_slack/credentials.py:43 has key 'slack-webhook' that matches existing registered type 'SlackWebhook' from /my_path/.venv/lib/python3.10/site-packages/prefect/blocks/notifications.py:83. The existing type will be overridden.
TypeError: Block.__new__() takes 1 positional argument but 2 were given
But the writing here still seems to be like how I’ve been using it (not using a Block). Maybe I missed another documentation update somewhere? Using: prefect 2.7.10 prefect-slack 0.1.1
1
z

Zanie

01/31/2023, 5:12 PM
cc @Andrew Huang
k

kiran

01/31/2023, 5:15 PM
Just tried this from @Anna Geller (thanks!) and it works but I’m still getting the warning. Which, I suppose, is fine at the moment, if it’s just a warning
FWIW, I seem to also be able to get it to work using:
# from prefect.blocks.notifications import SlackWebhook
from prefect_slack import SlackWebhook
but it shows up slightly differently than the other way (from blocks)
Screen Shot 2023-01-31 at 12.22.18.png
a

Andrew Huang

01/31/2023, 5:24 PM
SlackWebhook from prefect core is different from prefect-slack in the sense that prefect core’s webhook is powered by Apprise while prefect-slack uses Slack’s python client. I think at one point, we were planning to move the notification blocks out of the core library to reduce dependencies, but with Apprise, it was minimal dependencies to power many notification blocks, so we kept it. however, we should probably document that prefect-slack’s webhook is different and we might want to rename it. I’ll discuss with the team on how we want to approach prefect-slack
k

kiran

01/31/2023, 5:28 PM
Hi! OK, that’s good to know. Thanks. So it doesn’t matter which one I use (thinking about future)? Also, then, is this documentation no longer accurate? Since it doesn’t have anything about blocks and was giving me that warning and then Type error
z

Zanie

01/31/2023, 5:28 PM
What’s the expectation when you have both installed?
It seems less than ideal that the dispatch keys would collide and that the implementations aren’t compatibile.
a

Andrew Huang

01/31/2023, 5:30 PM
prefect_slack.SlackWebhook was copied over from prefect.SlackWebhook as it was at the time; however, prefect.SlackWebhook went through some refactoring with Apprise, so now they aren’t the same
k

kiran

01/31/2023, 5:30 PM
Originally I was just using the SlackCredentials way of doing it as it says in the docs I linked to. I don’t really care which I use, as long as I know which one I should be using (in thinking about the future)
from prefect_slack import SlackCredentials
from prefect_slack.messages import send_chat_message
a

Andrew Huang

01/31/2023, 5:32 PM
I think send_chat_message task has a bit more functionality, e.g. attachments and slack blocks
in the near future, we will be updating SlackWebhook’s block type slug so it doesn’t conflict with the core
k

kiran

01/31/2023, 5:35 PM
OK. The send_chat_message is what I’ve been using for months and now have started getting the warning and TypeError
Block._new_() takes 1 positional argument but 2 were given
so is there a way around this?
a

Andrew Huang

01/31/2023, 5:35 PM
in the farther out future, I believe we will be refactoring prefect-slack’s tasks as block methods, maybe SlackMessage()
can you share how you instantiate slack_credentials?
k

kiran

01/31/2023, 5:38 PM
Also, FWIW, I also have been gravitating toward using my own “DataEngineer” slackbot app because I’d been unable to mention my slack user ID or my slack team user ID in failure notifications. I could do this in Prefect 1 but not 2
from prefect import flow
from prefect.blocks.system import Secret
from prefect_slack import SlackCredentials
from prefect_slack.messages import send_chat_message

@flow
def begin_notify_flow(channel_name: str, flow_name: str):
    TOKEN = Secret.load("slack-bot-token").get()

    send_chat_message(
        slack_credentials=SlackCredentials(TOKEN),
        channel=channel_name,
        text=f":`{flow_name}` flow run is starting",
    )

    return
But this is using my slackbot token
And, to clarify, I have different “notify flows” because I put them in a try/except so I could get the failures. Since it doesn’t work totally the same as Prefect 1 with the contexts
a

Andrew Huang

01/31/2023, 5:41 PM
SlackCredentials(TOKEN)
do you use
token=TOKEN
I don’t think you can instantiate blocks without kwargs
k

kiran

01/31/2023, 5:42 PM
I never used it before but I can try now hold on
a

Andrew Huang

01/31/2023, 5:42 PM
in regards to try/except, I believe you can now use automations
for “my slack user ID or my slack team user ID in failure notifications” can you elaborate?
k

kiran

01/31/2023, 5:47 PM
OK. The
token=TOKEN
worked, when I never had to do it before
For IDs, I mean that I load in my slack user ID (e.g., 12345AB) and it mentions me when things fail
But the Prefect notifications write out the actual ID and not
@kiran
Or at least, that’s what was happening at the beginning of 2.0. I haven’t tried it again lately
So that’s why I went back to my own slackbot for now
a

Andrew Huang

01/31/2023, 5:50 PM
I see. Would you mind submitting an issue in prefect-slack and when we refactor we can add that functionality as well?
👍🏾 1
k

kiran

01/31/2023, 5:53 PM
So, given that it’s now working with
token=TOKEN
and the warning isn’t breaking anything, I think I’ll keep my current way of doing it for now
Thank you!
🙌 1
@Andrew Huang I just realized that this issue is the same one but I’m using
prefect==2.7.10
. Do you want me to file a new issue about the warning for that? Also, is there an issue template? (np if there’s not — I just want to make sure to use it if it there is, for the slack mentions issue)
a

Andrew Huang

01/31/2023, 6:30 PM
I just released prefect-slack v0.1.2 that should fix this atm there is none; haven’t updated it yet
👍🏾 1
k

kiran

01/31/2023, 6:31 PM
OK I’m going to just completely redo my environment. That’s like turn it off and back on again, right 🙃
thanks
a

Andrew Huang

01/31/2023, 6:33 PM
actually one moment…
need pypi approval for v0.1.2. should be out in 3 minutes
k

kiran

01/31/2023, 6:34 PM
ok np. No rush on my end. I have some meetings. I’ll check back later