https://dagster.io/ logo
#dagster-support
Title
# dagster-support
l

Lorenzo

02/02/2023, 2:06 PM
Hi everyone, I am stuck on what I think is a tiny problem, but I really can't figure it out. 🤯 What is a context? I am trying to set up a simple @op that runs a dbt model. the dbt_cli_resource need an argument that is "context" and I can't understand what kind of object/value should be placed inside. This is my simple code:
Copy code
@op
def dbt_op():
    cli_resource = dbt_cli_resource(context)
    cli_resource.run(models=["my_model"])
@job
def dbt_job():
    dbt_op()
And then I import my job in the repository obviously.
l

Lorenzo

02/02/2023, 3:39 PM
Thank you Jamie, I also read your reply in #dagster-support. 🙌🏻 The solution you sent me here still leaves me wondering what I am supposed to put in "context" 🙁
j

jamie

02/02/2023, 3:40 PM
oh you dont need to put anything in the context. it’s like a “magic” parameter. when you run the job in dagit, the dagster backend will create the context object and supply it for you
if you’re trying to execute an op in a unit test you can create a context yourself, is that what you’re looking for?
but outside of unit testing, you don’t need to make the context yourself
s

Sean Davis

02/02/2023, 8:33 PM
And just to make it a bit more concrete, the "context" object is usually an instance of the "OpExecutionContext" (https://docs.dagster.io/_apidocs/execution#contexts). Inside an op (or an asset), you can call the methods or accessors that are shown in the API documentation. These allow your op to access things like "resources" (https://docs.dagster.io/_apidocs/execution#dagster.OpExecutionContext.resources) and configuration (https://docs.dagster.io/_apidocs/execution#dagster.OpExecutionContext.run_config) as well as simpler things like the "run_id" (https://docs.dagster.io/_apidocs/execution#dagster.OpExecutionContext.run_id). Logging is also available (
<http://context.log.info|context.log.info>
for example).