Is there a recommended way of reading dbt model ta...
# integration-dbt
a
Is there a recommended way of reading dbt model tags into Dagster for alerting? Context: • We load our DBT models as assets with
load_assets_from_dbt_project
• We set an
owner
meta tag within
sources.yml
for our models • We want to tag these owners using
make_slack_on_run_failure_sensor
. How can we access the tags via the
context
within a custom
text_fn
that’s passed to
make_slack_on_run_failure_sensor
? Our runs also typically contain multiple assets, potentially with multiple owners. Could we programmatically determine the owners of only the subset of models that failed in the run? (edited)
r
With
@dbt_assets
, since you have access to customize the compute function, you can invoke slack in the body of your assets definition. We showed this in our release livestream a while back:

https://www.youtube.com/watch?v=yv97Xgbwwmo&t=1347s

The basic code is here. You can imagine that you could just: 1. Get the
run_results_json
to get failed models 2. Look into the manifest object to get the
meta
associated with each failed model 3. Send a Slack message for each owner in (2)
Copy code
@dbt_assets(manifest=dbt_manifest_path)
def jaffle_shop_dbt_assets(
    context: OpExecutionContext, dbt: DbtCliResource, slack: SlackResource
):
    dbt_build_invocation = dbt.cli(["build"], context=context)

    yield from dbt_build_invocation.stream()

    run_results_json = dbt_build_invocation.get_artifact("run_results.json")

    materialized_models_text = ""
    for result in run_results_json["results"]:
        if result["status"] == "success":
            materialized_models_text += (
                f"- `{result['unique_id']}`: {result['message']}\n"
            )

    slack.get_client().chat_postMessage(
        channel="team-nucleus-data-platform",
        text=(
            "The following dbt nodes have successfully materialized:\n"
            + materialized_models_text
        ),
    )
a
👑
Perfect, that’s just what I was looking for! Thank you
r
Great, this has come up multiple times now, so we’ll add this as an example in our docs
❤️ 1