https://dagster.io/ logo
#integration-dbt
Title
# integration-dbt
i

Ian Venter

03/22/2023, 2:36 AM
Hi, I am using Dagster with DBT. I am trying to mimic the effect of running 'materialize all' within Dagit. I have created a script that loads and materializes all my assets. The script runs fine, without any errors and my tables are materialized, however when i check my assets in Dagit they reflect as not materialized. I'm guessing there must be something missing in my script to get Dagit it recognize that the materialization has happened. My script is pretty simple and looks as follows:
Copy code
from dagster_dbt import dbt_cli_resource
import assets as assets
from assets import DBT_PROFILES, DBT_PROJECT_PATH
from dagster import load_assets_from_modules, materialize

#Assets loaded from dbt require a dbt resource, which is responsible for firing off dbt CLI commands.
#Using the 'dbt_cli_resource' resource, we can supply a dbt resource to the dbt project.
#
my_resources = {
    "dbt": dbt_cli_resource.configured(
        {
            "project_dir": DBT_PROJECT_PATH,
            "profiles_dir": DBT_PROFILES 
        },
    ),
}


all_assets = load_assets_from_modules([assets])

if __name__ == "__main__":
    materialize(assets=all_assets, resources=my_resources)
r

rex

03/22/2023, 2:59 AM
Just to note,
materialize
and
materialize_to_memory
are meant for usage in tests. The metadata that Dagit reads from is determined by
$DAGSTER_HOME
, so if you want this script to write to the same store as your Dagit instance,
$DAGSTER_HOME
should be set and be the same value in the process that runs your script and in the process that runs your webserver.
👍 1
s

sandy

03/22/2023, 5:25 PM
Not sure if this is helpful for you, but you could also use the
dagster asset materialize
command line interface
👍 1
i

Ian Venter

03/25/2023, 9:22 AM
Hi @sandy, that is super helpful. I've got it working with your approach. Thanks!
7 Views