Mars
07/11/2022, 9:09 PM.env
files to load secrets from os.environ
after prefect
module import time? I want to use a PrefectSecret
instead of an EnvVarSecret
in my code, and I don’t want to hack the code between Prefect/EnvVar for local dev. Local context secrets should work well for overriding the PrefectSecret values, but it’s not working the way I expect.
My debugger is telling me the context and secrets are set once, during import prefect
, which means the secrets are fixed before I can load a dotenv file using my library of choice. The following pseudocode doesn’t work:
import prefect
import environs # .env support. .env not loaded yet.
with Flow() as flow:
PrefectSecret("MY_SECRET")
if __name__ == "__main__":
# For local testing
env = environs.Env()
env.read_env(".env") # Load my custom PREFECT__CONTEXT__SECRETS into os.environ
flow.run() # Ignores new os.environ
Kevin Kho
07/11/2022, 9:11 PM