Hey, I am having trouble running a dbt prefect flow, and the documentation around this is very confusing, bordering on misleading and incomplete. Here is my flow
import os
from prefect import flow, task
from prefect_dbt import DbtCliProfile, DbtCoreOperation, SnowflakeTargetConfigs
from prefect_snowflake.credentials import SnowflakeCredentials
from prefect_snowflake.database import SnowflakeConnector
from prefect.context import FlowRunContext
@flow
def trigger_dbt_data_build(client: str, warehouse: str = "COMPUTE_WH"):
flow_run_name = FlowRunContext.get().flow_run.dict().get("name")
credentials = SnowflakeCredentials(
user=os.environ.get("SNOWFLAKE_USER"),
password=os.environ.get("SNOWFLAKE_PASSWORD"),
account=os.environ.get("SNOWFLAKE_ACCOUNT"),
role="ACCOUNTADMIN",
)
connector = SnowflakeConnector(
# schema=f"{client_name.upper()}_STG",
schema="dbt_zmunro",
threads=8,
database="RAW",
warehouse=warehouse,
credentials=credentials,
query_tag=f"dbt-data-build-{client}-{flow_run_name}",
)
target_configs = SnowflakeTargetConfigs(
connector=connector,
extras={
"retry_on_database_errors": True,
"connect_retries": 0,
"connect_timeout": 600,
"retry_all": False,
"reuse_connections": False,
},
)
dbt_cli_profile = DbtCliProfile(
name="prefect-snowflake-dev",
target="dev",
target_configs=target_configs,
)
return DbtCoreOperation(
commands=[
f'dbt build --select +somemodel --vars \'{{"client_schema":"{client.upper()}_STG"}}\''
],
dbt_cli_profile=dbt_cli_profile,
overwrite_profiles=True,
project_dir="/workflows/dbt/",
).run()
I am getting an error because the
DbtCoreOperation
cant find my
dbt_cli_profile
correctly. I am trying to follow the documentation here:
https://prefecthq.github.io/prefect-dbt/cli/credentials/#prefect_dbt.cli.credentials
That documentation doesn't say how to use this
dbt_cli_profile
object with the
DbtCoreOperation
function though. And I am confused as to how blocks relate to this all as well. Should I not be creating these credential objects each flow run and instead just do it once and save it in a block? where does this block get saved if I am not using prefect cloud?