<@ULVA73B9P> how do I change the name of the task ...
# ask-marvin
j
@Marvin how do I change the name of the task that gets generated when calling
run_dbt_test()
?
m
You can change the name of the task generated by
run_dbt_test()
by passing the
name
parameter. Below is an example code snippet:
Copy code
python
from prefect import flow
from prefect_dbt.cli.tasks import run_dbt_test

@flow
def dbt_flow():
    run_dbt_test(
        project_dir="/path/to/project",
        name="Custom DBT Test Task Name"
    )

if __name__ == "__main__":
    dbt_flow()
The parameter
name
allows you to set a custom name for the Prefect task. For more details, you can check out the Prefect documentation here. If you need further assistance, you might find it useful to check the related GitHub pull request here.
j
@Marvin you can't do that because the parameter is not defined. It throws a ParameterBindError
m
It appears there's no direct way to set a custom name for the task generated by
run_dbt_test()
. However, you can wrap the task in your own Prefect task and set the name manually. Here's an example:
Copy code
python
from prefect import flow, task
from prefect_dbt.cli.tasks import run_dbt_test

@task(name="Custom DBT Test Task Name")
def custom_run_dbt_test(project_dir, profiles_dir=None, overwrite_profiles=False, dbt_cli_profile=None, create_artifact=True, artifact_key="dbt-test-task-summary"):
    run_dbt_test(
      project_dir=project_dir,
      profiles_dir=profiles_dir,
      overwrite_profiles=overwrite_profiles,
      dbt_cli_profile=dbt_cli_profile,
      create_artifact=create_artifact,
      artifact_key=artifact_key
    )

@flow
def dbt_flow():
    custom_run_dbt_test(project_dir="/path/to/project")

if __name__ == "__main__":
    dbt_flow()
By defining your own task, you can specify a custom name and call
run_dbt_test()
within it. For further reference, you can look at the relevant Prefect documentation: - Prefect Tasks: https://docs.prefect.io/latest/concepts/tasks/ - Prefect Dbt CLI Commands: https://docs.prefect.io/latest/integrations/prefect-dbt/cli/commands/ If you have any more questions, feel free to ask!
j
I know, but then it creates a task inside the task