https://prefect.io logo
k

kevin

12/30/2020, 5:37 PM
Hey guys, just a quick question: does the
defaults_from_attrs
decorator on
PostgresFetch.run()
allow me to build a bunch of queries out like this:
Copy code
with Flow('foo') as flow:
    pw = PrefectSecret('pass')
    pg_template = PostgresFetch(host='host',user='user',db_name='name', port=1234)
    pg_query1 = pg_template(password=pw, query='select * from foo;')
    pg_query2 = pg_template(password=pw, query='select * from bar;')
j

josh

12/30/2020, 6:08 PM
Looking at the code for the task it seems like that should be possible. Are you seeing otherwise?
k

kevin

12/30/2020, 6:09 PM
I haven't executed the code yet, I was just wondering if I was going in the right direction and using the internal functions correctly
It seems kind of odd to me that password is deferred to the
run()
method on the task rather than at instantiation
j

josh

12/30/2020, 6:11 PM
The
PrefectSecret
task is a preferred way of passing sensitive information to the task and for the value to be read it needs to be passed in at runtime
k

kevin

12/30/2020, 6:12 PM
gotcha, so can I do something like
PrefectSecret(os.environ.get('db_pw'))
?
j

josh

12/30/2020, 6:13 PM
If the value in your environment for
db_pw
is the name of the secret then you should be good to go. Take a look at this doc on secrets for some more information about how they are used: https://docs.prefect.io/core/concepts/secrets.html
k

kevin

12/30/2020, 6:14 PM
awesome, thanks for your help!