Ben Fogelson
03/26/2020, 11:02 PMParameter
whose default is the value of another Parameter
? Something like
from prefect import task, Flow, Parameter
@task
def add(x, y):
return x + y
with Flow('flow') as flow:
a = Parameter('a', default=0)
b = Parameter('b', default=a)
c = add(a, b)
Chris White
from prefect import task, Flow, Parameter
@task
def add(x, y):
return x + y
@task
def b(a, _b):
"Stand-in for the b Parameter"
return a if _b is None else _b
with Flow('flow') as flow:
a = Parameter('a', default=0)
_b = Parameter('_b', default=None, required=False)
c = add(a, b(a, _b))
Ben Fogelson
03/26/2020, 11:18 PMfrom prefect import task, Flow, Parameter
@task
def add(x, y):
return x + y
@task
def default_param(param, default):
return param if param else default
with Flow('flow') as flow:
a = Parameter('a', default=0)
_b = Parameter('b', default=None, required=False)
b = default_param(_b, a)
c = add(a, b)
Chris White
Marvin
03/26/2020, 11:19 PMBen Fogelson
03/26/2020, 11:36 PMrun
method of `Parameter`:
def run(self) -> Any:
params = prefect.context.get("parameters") or {}
if self.required and self.name not in params:
self.logger.debug(
'Parameter "{}" was required but not provided.'.format(self.name)
)
raise prefect.engine.signals.FAIL(
'Parameter "{}" was required but not provided.'.format(self.name)
)
if self.name not in params and isinstance(self.default, Parameter):
return self.default.run()
return params.get(self.name, self.default)
Are there any corner cases that would trip this up that I’m not aware of?Chris White
Ben Fogelson
03/26/2020, 11:39 PM