Hey guys, just a quick question: does the `default...
# ask-community
k
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
Looking at the code for the task it seems like that should be possible. Are you seeing otherwise?
k
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
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
gotcha, so can I do something like
PrefectSecret(os.environ.get('db_pw'))
?
j
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
awesome, thanks for your help!