Hi, I am using Dagster with DBT. I am trying to m...
# integration-dbt
i
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
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
Not sure if this is helpful for you, but you could also use the
dagster asset materialize
command line interface
👍 1
i
Hi @sandy, that is super helpful. I've got it working with your approach. Thanks!