Dear prefect people, we have some troubles on run...
# ask-community
r
Dear prefect people, we have some troubles on running our dbt model with prefect. Using dbt run, we are able to run the model locally, however in prefect, we only get the following error
ERROR - prefect.DbtShellTask | Command failed with exit code 1
Any thoughts on what could be wrong or how to get further information and debug the flow are appreciated! 🙂
k
Hi @Robin! When you’re able to run locally and can’t run it in Cloud, it could be missing dependencies on the agent. What agent are you using? Did you try using
log_stderr=True
to get the error?
r
Ah for clarification: • without prefect,
dbt run
works locally • with prefect,
dbt run
works neither locally nor in cloud
k
Ah gotcha. Can you post how you’re using the
DbtShellTask
? Also try the
log_stderr
.
r
Copy code
from prefect import Flow

from prefect.tasks.dbt import DbtShellTask

PROFILES = "."

with Flow("dbt_flow") as flow:

    task = DbtShellTask(
        environment="Deployment",
        profiles_dir=PROFILES,
    )(command="dbt debug")

flow.run()
where the
dbt_flow.py
is in the dbt project folder where the
dbt_project.yml
lies and
profiles.yml
is in the same folder
PS: Alternatively, we also tried to run
dbt_flow.py
from another folder by specifying
--profiles-dir ../dbt_project
k
Am I missing it? Not quite seeing where
dbt_flow.py
is written in the Flow
Oh got it ok. I haven’t used dbt myself but let me look at the task
How are you testing this at the moment?
flow.run()
? The task usage looks good to me. Let’s try the
log_stderr=True
r
Still only getting
INFO - prefect.TaskRunner | FAIL signal raised: FAIL('Command failed with exit code 1')
I actually also get the following warning:
Copy code
UserWarning: Tasks were created but not added to the flow: {<Task: Task>}. This can occur when `Task` classes, including `Parameters`, are instantiated inside a `with flow:` block but not added to the flow either explicitly or as the input to another task. For more information, see <https://docs.prefect.io/core/advanced_tutorials/task-guide.html#adding-tasks-to-flows>.
  next(self.gen)
k
I guess my suggestion would be to leave
profiles_dir
blank and use
dbt debug
to see if that’ll work. It will create a
profiles.yml
for you. We can try this and see if it works?
I don’t know enough dbt to even get the debug to work. My last resort suggestion would be to use the ShellTask . Also, there are a couple of users of this DbtShellTask here. I would try searching the Slack history and maybe pinging one of those threads.
r
hmm, ok
k
Sorry about that. I’ll keep trying though 😢
r
Thanks for your help!
I am wondering why there is no more detailed error message
it is hard to debug since it only gives that very hgih level error message 🤷
k
About that, when I use something like:
Copy code
task = DbtShellTask(
        profile_name='default',
        environment="Deployment",
        profiles_dir="/tmp/",
        return_all=True,
        log_stderr=True
    )
I do see a bit more error messages (I have issues installing dbt). Do you not see those other logs?
r
nope, I only get that one line 🤔
k
Can we try corrupting the command like
dbbtt debug
? Just to see if you’ll get an error like
dbbtt not found
r
good point
still the same error message
So I guess something with the
ShellTask
goes wrong? 🤔
k
Why don’t we try this ?
Add
stream_output=True
r
still no change 🤔
I also tried
command="ls"
or "dir" but not output
so I wonder whether that is an os issue 🤔
k
That’s really weird. I get logs with
ls
. I’m thinking the same. I’m on a mac. Are you on a linux or mac? There were changes to the ShellTask in 0.14.15 and 0.14.16 but I don’t think they should be relevant for this. Just checking, what Prefect version are you on?
Does ShellTask also do the same thing with
ls
?
r
ah
just changed machines and on my mac it works as well
so maybe windows issue 🤔
I will see whether I can get the dbt flow running on my mac
k
r
That indeed seems to explain it 🙂
k
Ok let’s hope DbtShellTask gives some informative messages now 🤞
r
So I need to add bash exe to path?
for windows?
will first try on mac, but just to understand want to do on windows either way
k
This fix was released in 0.14.16: https://github.com/PrefectHQ/prefect/pull/4403
but yes you need
bash
in
PATH
on windows
r
got it
I guess it would be good for windows users if that message is posted if the shelltask is executed on windows and fails?
k
That’s a good suggestion. I can bring this up with the team and maybe open an issue about it
Thank you for your patience by the way!
🙏 1
r
Thank you for the support!
m
Hi, I'll reopen this thread again 🙂 I have the same issues as Robin but add bash to path does not work so far for me and I use prefect 0.14.21 so the shell fix from april should be included imho. Thats my code
Copy code
with Flow(name="dbt_flow") as f:
    task = DbtShellTask(
        log_stderr=True,
        log_stdout=True,
        return_all=True,
        stream_output=True,
        profiles_dir=profile_path

    )(command='dbt run --models myModel')

out = f.run()
That's the output
Copy code
[2021-06-09 16:06:15+0200] INFO - prefect.FlowRunner | Beginning Flow run for 'dbt_flow'
[2021-06-09 16:06:15+0200] INFO - prefect.TaskRunner | Task 'DbtShellTask': Starting task run...
[2021-06-09 16:06:15+0200] INFO - prefect.DbtShellTask | /bin/bash: C:\Users\M7856~1.\AppData\Local\Temp\prefect-5yoqhqg_: No such file or directory
[2021-06-09 16:06:15+0200] ERROR - prefect.DbtShellTask | Command failed with exit code 127
[2021-06-09 16:06:15+0200] INFO - prefect.TaskRunner | FAIL signal raised: FAIL('Command failed with exit code 127')
[2021-06-09 16:06:15+0200] INFO - prefect.TaskRunner | Task 'DbtShellTask': Finished task run for task with final state: 'Failed'
[2021-06-09 16:06:15+0200] INFO - prefect.FlowRunner | Flow run FAILED: some reference tasks failed.
What I did wrong? Thanks for help Best Michael
k
So you’re on Windows and adding bash to the path did not work in running the DbtTask?
How did you add badh to the path?
m
maybe it will be a littlebit emberrassing for me 😄 but I just added in the enviorment variables on windows to path: C:\Windows\System32\bash.exe
k
I think that’s right…can you go in the command line and try using it to confirm it works?
m
yes I enterd bash in cmd and it starts the bash
I use VS Code for developing but even with Jupytier Notebook doesn't worked for me
k
What error do you get when using the ShellTask?
m
the same only with ShellTask.... but he is trying to access "c:\users\ ..." should that not be like "mnt/c/user/ ..." is that some how possible to change the path?
k
This is a bit beyond me. Can you open a new thread in the community channel so I can direct it to the team easily?
m
done
Thanks for your support 🙂