Ken Nguyen
04/17/2022, 10:17 PMtest_param = Parameter('test_param', default="default_val")
function(test_param)
Where I got an AttributeError:
AttributeError: 'Parameter' object has no attribute
function(test_param.value)
to input just the string value of the parameter<Parameter: dbt_command>
). Why is there a different behaviour between the two tasks?
@task
def print_param(param):
<http://logger.info|logger.info>(param)
<http://logger.info|logger.info>(type(param))
with Flow("flow-name", run_config=RUN_CONFIG, storage=STORAGE) as flow:
dbt_command = Parameter('dbt_command', required=True)
print_param(dbt_command)
dbt_run = DbtShellTask(
command = dbt_command,
...,
dbt_kwargs={
...
},
)
Kevin Kho
04/18/2022, 2:08 AMKen Nguyen
04/18/2022, 5:17 AMKevin Kho
04/18/2022, 1:38 PMwith Flow("flow-name", run_config=RUN_CONFIG, storage=STORAGE) as flow:
dbt_command = Parameter('dbt_command', required=True)()
print_param(dbt_command)
The first parenthesis is the init and the second one is the run. The run will force it.Ken Nguyen
04/18/2022, 4:57 PMTask 'DbtShellTask': Exception encountered during task execution!
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 880, in get_task_run_state
value = prefect.utilities.executors.run_task_with_timeout(
File "/usr/local/lib/python3.8/site-packages/prefect/utilities/executors.py", line 468, in run_task_with_timeout
return task.run(*args, **kwargs) # type: ignore
File "/usr/local/lib/python3.8/site-packages/prefect/utilities/tasks.py", line 456, in method
return run_method(self, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/tasks/dbt/dbt.py", line 192, in run
return super(DbtShellTask, self).run(
File "/usr/local/lib/python3.8/site-packages/prefect/utilities/tasks.py", line 456, in method
return run_method(self, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/tasks/shell.py", line 131, in run
tmp.write(command.encode())
AttributeError: 'Parameter' object has no attribute 'encode'
Kevin Kho
04/18/2022, 5:02 PMKen Nguyen
04/18/2022, 5:21 PMKevin Kho
04/18/2022, 5:22 PMfrom prefect import task, Flow, Parameter
import prefect
@task
def abc(x):
<http://prefect.context.logger.info|prefect.context.logger.info>(x)
return x
with Flow("..") as flow:
test = Parameter("test", required=True)
abc(test)
flow.run(parameters={"test": 2})
Ken Nguyen
04/18/2022, 5:28 PMKevin Kho
04/18/2022, 5:30 PMKen Nguyen
04/18/2022, 5:42 PMKevin Kho
04/18/2022, 5:47 PMwith Flow("..") as flow:
test = Parameter("test", required=True)
DbtShellTask(__init__here)(..., test)
which will workKen Nguyen
04/18/2022, 6:02 PMKevin Kho
04/18/2022, 6:12 PM