Hello. I’m playing around with the slack notificat...
# ask-community
d
Hello. I’m playing around with the slack notification and trying to locally set the secret but keep getting the error that
ValueError: Local Secret "SLACK_WEBHOOK_URL" was not found.
I tried the suggestions mentioned here https://github.com/PrefectHQ/prefect/blob/b4c08b15b386107e2c1afb7fed35dca15b683cdd/src/prefect/client/secrets.py but wasn’t getting anything to work locally. Threading what I currently have
Copy code
import os

from prefect import Flow, task
from prefect.utilities.notifications import slack_notifier

os.environ["PREFECT__CONTEXT__SECRETS__SLACK_WEBHOOK_URL"] = "XXX"

handler = slack_notifier()

@task(state_handlers=[handler])
def add(x, y):
    return x + y

with Flow("Testing") as flow:
    add(7,8)

flow.run()
j
Context is loaded at the import time of the library unless otherwise explicitly overridden which means the secret should be set prior to the import of prefect. In this case I would recommend setting it outside your script: e.g.
Copy code
export PREFECT__CONTEXT__SECRETS__SLACK_WEBHOOK_URL="..."
or it could be placed in your
~/.prefect/config.toml
under
Copy code
[context.secrets]
SLACK_WEBHOOK_URL="..."
c
yea adding to what @josh said, Setting an environment variable via os will only work if you fork / spawn a new process. If you want it to be all in the script you can also add the secret directly to context in place of your os call
d
Thanks. I swear I had tried
Copy code
prefect.context.setdefault("secrets", {})
prefect.context.secrets["SLACK_WEBHOOK_URL"] = "XXX"
And it didn’t work but it did now. So I’ll take it and run
👍 1
c
@Marvin archive “Issue setting local secrets”