https://prefect.io logo
h

Hamed Sheykhlou

12/09/2020, 8:48 AM
Hi I want to use SecretResult in my project. for learning purposes, I write an example project.
Copy code
import requests
from prefect import Flow, task

from prefect.engine.results import SecretResult


@task(name='extract_task')
def extract():
    res = requests.get('<https://jsonplaceholder.typicode.com/todos/1>')
    res_txt = res.text
    print(res_txt)
    return res_txt


@task()
def load():
    """Print the data to indicate it was received"""
    print(SECRET_RESULT.location)
    res_txt = SECRET_RESULT.read('secret1')
    print("Here's your data: {}".format(res_txt))


with Flow("Callback-Example") as flow:

    SECRET_RESULT = SecretResult(extract, location='somewhere.json')

    e = extract()
    l = load()
    l.set_upstream(e)

flow.run()
but when I run it, gave some error on prefect source:
Copy code
File "/home/hamed/PycharmProjects/etlprefectcloud/venv/lib/python3.8/site-packages/prefect/engine/results/secret_result.py", line 38, in read
    new.value = self.secret_task.run(name=location)
TypeError: extract() got an unexpected keyword argument 'name'
its on
prefect/engine/results/secret_result.py
line 38:
new.value = self.secret_task.run(name=location)
. and if I delete the name argumans, it works. am I using the SecretResult wrong way?
s

Sébastien

12/09/2020, 12:01 PM
I'm not very familiar with Prefect Secrets, but your usage looks like you're trying to use a Prefect Secrets Task — https://docs.prefect.io/api/latest/tasks/secrets.html#prefectsecret If you're looking for regular secrets, and not secret tasks, you can just use
Secret
https://docs.prefect.io/core/concepts/secrets.html#local-context
SecretResult
looks like it's only meant to be a return type — not something you create yourself.
⬆️ 1
h

Hamed Sheykhlou

12/09/2020, 2:16 PM
Have anybody an example of using SecretResult?
1
3 Views