I'm trying to trigger a cli dbt command in prefect...
# prefect-dbt
t
I'm trying to trigger a cli dbt command in prefect but getting this error
Copy code
[0m20:39:10  Encountered an error:
Compilation Error
  dbt found 3 package(s) specified in packages.yml, but only 0 package(s) installed in dbt_packages. Run "dbt deps" to install package dependencies.
here's my command
Copy code
trigger_dbt_cli_command.with_options(name=f"transform").submit(
        command=f"dbt run --models some_model",
        profiles_dir=dir,
        project_dir=dir,
    )
I see the dbt deps get installed when I build my docker container so not quite sure what's happening
s
I'd speculate that the dependencies aren't getting installed in the correct directory.
t
hmmm that's definitely possible. let me tweak some stuff in my dockerfile and confirm. thank you for the suggestion @Sean Williams!
s
It might be easier to use
DbtCoreOperation
because you can supply more than one dbt command, and manage the dependencies that way.
Copy code
from prefect_dbt.cli.commands import DbtCoreOperation
from prefect import flow

@flow
def trigger_dbt_flow() -> str:
    result = DbtCoreOperation(
        commands=["dbt deps", "dbt build -t prod"],
        project_dir="prefect_demo",
        profiles_dir="~/.dbt"
    ).run()
    return result

if __name__ == "__main__":
    trigger_dbt_flow()
t
can I stream the output using DbtCoreOperation? or would I need to wait for the task to complete before seeing the output?
s
You should be able to see the logs as they're generated
t
yes! I'm able to see the output of the dbt run now, just not the dbt deps but running them both in one is working for me now
🎉 1
thank you sean!
last question, is there an easy way to specify the target in my profile as well? or should I add
--target prod
to my commands list?
s
The top level target in your
profiles.yml
file is the default. You only need to supply a target if you have additional targets and you want to override the default
t
correct, we have a default profile we use for local dev, and I want to apply the prod profile in my flow
s
How are you creating that file in your container for production?
I think your options are to change the default target in the
profiles.yml
in prod, or supply the target flag
t
it's in our profiles.yml in our repo, not via a block
I can pass in the --target param in the command
s
Yep!
It's in the example I pasted above
-t == --target
🙌 1
✅ 1
t
thank you again sean!!