https://prefect.io logo
Title
d

dhume

02/10/2020, 6:59 PM
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
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

josh

02/10/2020, 7:04 PM
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.
export PREFECT__CONTEXT__SECRETS__SLACK_WEBHOOK_URL="..."
or it could be placed in your
~/.prefect/config.toml
under
[context.secrets]
SLACK_WEBHOOK_URL="..."
c

Chris White

02/10/2020, 7:07 PM
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

dhume

02/10/2020, 7:09 PM
Thanks. I swear I had tried
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

Chris White

02/11/2020, 4:24 PM
@Marvin archive “Issue setting local secrets”