<@ULVA73B9P> I'm trying to invoke `dbt source fres...
# ask-marvin
n
@Marvin I'm trying to invoke
dbt source freshess
with PrefectDbtRunner like this
PrefectDbtRunner.invoke(["source", "freshness"])
but getting an error. Other commands like build works fine. How do I invoke this command?
Copy code
Task run encountered an exception ValueError: Failed to invoke dbt command 'sourcefreshness': Runtime Error\n  No dbt_project.yml found at expected path
m
thought for 349.9 seconds
You’re very close — the
invoke(["source", "freshness"])
syntax is correct. The error you’re seeing is coming from dbt, not Prefect: dbt can’t find a
dbt_project.yml
in the working directory. That’s why
build
may work for you (depending on how your runner is initialized), but
source freshness
fails. Ways to fix it: - Run from your dbt project directory (or set
DBT_PROJECT_DIR
) - Pass the project (and profiles) directories as flags in your invoke call - Configure the runner with
PrefectDbtSettings
that specify the project/profiles dirs Examples: 1) Pass flags inline
Copy code
runner = PrefectDbtRunner(...)
runner.invoke([
    "source", "freshness",
    "--project-dir", "/path/to/your/dbt_project",
    "--profiles-dir", "/path/to/your/.dbt"
])
2) Configure once via settings
Copy code
from prefect_dbt import PrefectDbtRunner, PrefectDbtSettings

settings = PrefectDbtSettings(
    project_dir="/path/to/your/dbt_project",
    profiles_dir="/path/to/your/.dbt",
)
runner = PrefectDbtRunner(settings=settings)
runner.invoke(["source", "freshness"])
Notes: - The
'sourcefreshness'
you see in the error string is just how the error message is formatted — dbt still expects two tokens (
source
and
freshness
) and your call is correct. - You can also set
DBT_PROJECT_DIR
and/or
DBT_PROFILES_DIR
in your environment if you prefer not to pass flags. If you’d rather use the helper task, Prefect also exposes:
Copy code
from prefect_dbt.cli.commands import run_dbt_source_freshness

await run_dbt_source_freshness(
    project_dir="/path/to/your/dbt_project",
    profiles_dir="/path/to/your/.dbt"
)
Docs for the Prefect dbt integration: Prefect dbt integration docs If this still fails, can you share: - How you’re constructing
PrefectDbtRunner
(are you passing a
manifest
?) - Where
dbt_project.yml
lives at runtime (container path, working dir, etc.) - Whether you have
DBT_PROJECT_DIR
or
DBT_PROFILES_DIR
set in the environment?
n
@Marvin I am already passing settings like that. As I mentioned other commands are working so its not like the project isn't there. Here is the complete call.
Copy code
settings = PrefectDbtSettings(profiles_dir="/some/path", project_dir="/some/path")
runner = PrefectDbtRunner(settings=settings)
runner.invoke(["source", "freshness"])
m
thought for 57.1 seconds
Thanks for the details — your syntax is correct. The
'sourcefreshness'
you see is just how the error message is concatenated; dbt still expects two tokens (
"source"
,
"freshness"
). Given you’re already passing
PrefectDbtSettings
, this looks like the `project_dir`/`profiles_dir` from settings aren’t being picked up for this specific subcommand. Two reliable workarounds: - Pass the dirs as flags in the invoke call (putting global flags before the subcommand tends to be most robust):
Copy code
runner.invoke([
    "--project-dir", "/some/path",
    "--profiles-dir", "/some/path",
    "source", "freshness",
])
If that doesn’t work in your environment, try flags after the subcommand:
Copy code
runner.invoke([
    "source", "freshness",
    "--project-dir", "/some/path",
    "--profiles-dir", "/some/path",
])
- Use the helper task which wires this up for you:
Copy code
from prefect_dbt.cli.commands import run_dbt_source_freshness

await run_dbt_source_freshness(
    project_dir="/some/path",
    profiles_dir="/some/path",
)
If you still see the same error: - What versions of
prefect-dbt
and
dbt-core
are you running? - Can you confirm that
/some/path/dbt_project.yml
exists inside the runtime environment (e.g., container path)? - Please try
print(runner.settings)
right before invoke to confirm the values at runtime. Docs for reference: Prefect dbt integration docs
n
This is a bug. Report here