I have many tasks distributed across files, and on...
# ask-community
j
I have many tasks distributed across files, and one slack_notifier handler that they all import and utilize. What is a good pattern for disabling/using a different handler for local dev. I cannot run flows locally unless i change the handler because i get a
ValueError: Local Secret "SLACK_WEBHOOK_URL" was not found.
I tried this pattern, but it doesnt seem to work because the secrets are not actually checked until flows are run, so there is no exception defining the initial handler:
Copy code
try:
    handler = slack_notifier()
except:
    handler = local_state_handler()
I also tried this pattern, but it did not seem to work either:
Copy code
if Secret("SLACK_WEBHOOK_URL").exists():
    handler = slack_notifier()
else:
    handler = local_state_handler
k
I think you can set the secret locally like

this

to mirror the Cloud Secret. Or you can turn off local secrets so that even local runs will pull the Cloud Secret
You can set an env variable 
"PREFECT__CLOUD__USE_LOCAL_SECRETS": "false"
j
Thanks Kevin. good workaround, but i would actually prefer to have a different handler for local dev, and just figured the presence of the secret was a good way to determine that. No need for our team to get slack notifications while i mess things up during development
Is there a better way to set the handler based on whether or not a run is being executed by prefect cloud?
k
Ah I see what you mean. There is a context variable that does say if it’s a Cloud run. We can use that context in the state handler with an if-else to trigger the Slack notification. Let me look for it
Cloud attaches this to the context
running_with_backend: True
. You can look for it in your state handler
j
Great! thanks Kevin
👍 1