# Should dbt run its tests against the tmp table before committing?

**URL:** <https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027>\
**Category:** Help\
**Tags:** testing\
**Created:** [October 7, 2022, 10:40am UTC](https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027 "2022-10-07T10:40:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![obar1](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/obar1/32/1221_2.png) [@obar1](https://discourse.getdbt.com/u/obar1)\
**Post date:** [October 7, 2022, 10:40am UTC](https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027/1 "2022-10-07T10:40:59Z")

</div>

using test is a must but looking into the debug log of the jobs where I added some tests to some models in the related yml I see something I would like to have confirmation on:

```auto
create table
    "dwh"."data"."traffic__dbt_tmp"
...
alter table "dwh"."data"."traffic__dbt_tmp" rename to "traffic"
...
test.dwh.not_null_traffic_user_id

```

why does not do test on the tmp and exit in case of failure but it does on the final model?

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [October 10, 2022, 3:22am UTC](https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027/2 "2022-10-10T03:22:03Z")

</div>

@obar1 what command did you use to invoke dbt?

If you used `dbt run`, then it will create the models without testing them. If you used `dbt build`, it will create the models and then test them, and if they fail they will prevent downstream models from being built.

Running tests against the temp model and only committing if they pass is an interesting idea; I suspect the answer to your question is that the majority of dbt’s models are views instead of tables so don’t go through this interstitial state.

As noted above, `dbt build` will stop downstream models from being built if the test fails, but that still means that the failing model is in prod.

From what you’re describing, you might want to look at [Performing a blue/green deploy of your dbt project on Snowflake](https://discourse.getdbt.com/t/performing-a-blue-green-deploy-of-your-dbt-project-on-snowflake/1349); a blue/green deploy is where you “swap out” the production version of your tables only after all the tests have passed.

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [October 12, 2022, 4:14am UTC](https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027/3 "2022-10-12T04:14:48Z")

</div>

Coming back to this - check out [Provide option to allow tests to be ran before a model's data is updated · Discussion #5687 · dbt-labs/dbt-core · GitHub](https://github.com/dbt-labs/dbt-core/discussions/5687) for the discussion around whether this is added to dbt Core in the future!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [October 19, 2022, 4:15am UTC](https://discourse.getdbt.com/t/should-dbt-run-its-tests-against-the-tmp-table-before-committing/5027/4 "2022-10-19T04:15:07Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
