I seem to be having a problem passing a `Parameter...
# prefect-community
j
I seem to be having a problem passing a
Parameter
into the class constructor
__init__
of a task that has been subclassed from
prefect.Task
I am receiving a
prefect.Task
object instead of the value from the Parameter itself. I can't seem to figure out what I'm doing wrong.
s
Parameters
should be passed as runtime field values for other tasks. Tasks are initialized at registering time which means your parameter does not have a value yet.
upvote 1
a
Exactly as explained☝️ by Sylvain. I can only add: you could retrieve the parameter value from the context in the
run()
method of your task, as the run method, in contrast to
__init__
, gets evaluated at runtime. Something like:
Copy code
import prefect
from prefect import Task

class YourCustomTask(Task):
    def run(self):
        param = prefect.context["parameters"].get("parameter_name")
        print(f"Got parameter value: {param}")
🙌 1
s
Oh I didn't know you could access all parameters through the context. Could see that being useful ! Thanks Anna !
👍 1
j
Thanks guys. That helped clear things up
👍 1