https://dagster.io/ logo
#ask-community
Title
# ask-community
g

Gatsby Lee

07/18/2022, 6:10 PM
Hi, I’d like to run “dbt deps” before “dbt run”. can you share which way is recommended?
j

jamie

07/18/2022, 6:23 PM
cc @owen
g

Gatsby Lee

07/18/2022, 6:24 PM
thank you!
o

owen

07/18/2022, 6:32 PM
hi @Gatsby Lee! Are you using ops for this, or software-defined assets? and are you executing your job in a distributed manner (i.e. each step runs on a different node) or is everything running on the same machine?
g

Gatsby Lee

07/18/2022, 6:33 PM
I am currently trying to use ops
since I don’t know it is distributed or not, I guess it is not distributed.
in one container
o

owen

07/18/2022, 6:34 PM
got it -- you can make a
dbt_deps_op
pretty easily in that case. that would look something like
Copy code
@op(required_resource_keys={'dbt'})
def dbt_deps_op(context):
    context.resources.dbt.deps()
then you can hook up the built-in dbt_run_op with the dbt_deps op like this
Copy code
@job
def deps_and_run_job():
    dbt_run_op(start_after=dbt_deps_op())
g

Gatsby Lee

07/18/2022, 6:36 PM
I will try it. Thank you very much!!
o

owen

07/18/2022, 6:36 PM
no problem! I didn't directly test that code so it's possible there's a typo or something, let me know if you run into any issues 🙂
g

Gatsby Lee

07/18/2022, 6:39 PM
I have one following question.
how is the resource implementation looks like for
required_resource_keys={'dbt'})
?
I define resource sth like this for models
Copy code
dbt_resource_all_models = dbt_cli_resource.configured(
    {
        "project_dir": "../dbt_data_tf",
        "profiles_dir": "../dbt_data_tf",
    }
)
do I have to define a resource “dbt” for “deps” as well?
o

owen

07/18/2022, 6:45 PM
nope! both of these ops are requiring a resource named "dbt", so when you supply that resource to your job (
resource_defs={"dbt": dbt_resource_all_models, ...}
), both the dbt deps op and the dbt run op will use that same resource
g

Gatsby Lee

07/18/2022, 6:46 PM
ah i see.
Thank you very much!!
dagstir 1
hi. the api
deps
doesn’t exist.
AttributeError: 'DbtCliResource' object has no attribute 'deps'
o

owen

07/18/2022, 9:02 PM
ah sorry, my bad! I misremembered it being there -- you can do
context.resources.dbt.execute_cli("deps")
instead
g

Gatsby Lee

07/18/2022, 9:03 PM
ah.. Thank you. Thank you!!
let me try with it.
hmm. the
execute_cli
also doesn’t exist.
AttributeError: 'DbtCliResource' object has no attribute 'execute_cli'
do you know where I can find the api reference for DbtCliResource?
maybe this ? - c
o

owen

07/18/2022, 10:15 PM
double facepalm facepalm -- it's just
cli
(sorry again) and I'll grab the api docs for you
ah yeah that's it
g

Gatsby Lee

07/18/2022, 10:16 PM
hehe. np.
it helps me find the api reference
thank you again. 😄
o

owen

07/18/2022, 10:16 PM
no prob, appreciate your patience 🙂
❤️ 1
g

Gatsby Lee

07/18/2022, 10:17 PM
thank you for your reply 😄
r

Robert Lawson

11/09/2022, 2:27 PM
belated thanks to both of you for this thread!
was just helpful