# Scheduling DBT pipelines using two mandatory tags

**URL:** <https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743>\
**Category:** Help\
**Tags:** environments, orchestration-and-deployment\
**Created:** [December 19, 2022, 9:25pm UTC](https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743 "2022-12-19T21:25:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![And123](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@And123](https://discourse.getdbt.com/u/And123)\
**Post date:** [December 19, 2022, 9:25pm UTC](https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743/1 "2022-12-19T21:25:08Z")

</div>

I’m trying to find a solution for scheduling and tagging my models. I have two tags e.g. environment and schedule, where environment can take values like staging/production, while schedule can take values like daily/weekly/monthly. I want to only tag the final model of each data pipeline I have, and when I run my dbt command I want the entire pipeline (inlcuding upstream models) to run. However, I only want to run pipelines that are tagged with both an environment and schedule tag. Ultimately I’m looking for a solution for this task in DBT, however, the solution I’ve trying to get working is bumping into this problem below.

So the command I’ve being trying to use is `dbt run --select +tag:staging,+tag:daily` and this does work most of the time. However, if I have say pipeline A, and one of my upstream models (model 1) is a final model of another pipeline. Model 1 is tagged with staging and daily, while the final model of pipeline A (model 2) is tagged with production and weekly. To recap, model 1 is an upstream model of model 2.

If I run the following command for a completely separate pipeline B (not sharing any upstream models with pipeline A) `dbt run --select +tag:production,+tag:daily `. I wouldn’t expect any of my models from pipeline A to run (since model 1 and 2 would need to have the tags production and daily, and or be part of the upstream models of a model with those tags, and both of these cases are not true), however, model 1 ends up being run because of the way the intersection operator works. E.g. `+tag:production` will pick up model 2 and all it’s upstream models therefore picking up model 1, while `+tag:daily` will pick up model 1 because it has the daily tag. And because each intersection group picks up model 1, model 1 will run even though it shouldn’t have. To recap, although `dbt run --select +tag:production,+tag:daily ` works, and runs what I need, it also unintentionally runs a model it shouldn’t have.

Basically because of the current order of operations for DBT syntax selection, selection methods, then graph operators, then set operators I get this problem. If say the order was instead selection methods, then set operators, then graph operators this method would work. Is there anyway around this so that I could make this work? If not, does anyone have any ideas for how I could get this to work?

Thanks!

---

<div class="post-metadata">

**Author:** ![minhajpasha](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/minhajpasha/32/1159_2.png) [@minhajpasha](https://discourse.getdbt.com/u/minhajpasha)\
**Post date:** [December 20, 2022, 6:48pm UTC](https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743/2 "2022-12-20T18:48:45Z")

</div>

Hello - Please use --exclude flag to skip the models which are not required in your pipeline

–exclude tag:model1/2 [add tag as : model1/2] to model

---

<div class="post-metadata">

**Author:** ![And123](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@And123](https://discourse.getdbt.com/u/And123)\
**Post date:** [December 20, 2022, 8:31pm UTC](https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743/3 "2022-12-20T20:31:45Z")

</div>

Thanks for the reply. Although I’m looking for a more general solution approach, as I won’t always know what model 1 and 2 are if there are lots of pipelines being scheduled.

---

<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:** [January 10, 2023, 1:02am UTC](https://discourse.getdbt.com/t/scheduling-dbt-pipelines-using-two-mandatory-tags/5743/4 "2023-01-10T01:02:17Z")

</div>

I think your diagnosis of the problem (the order of evaluation) is correct, so I think you’d be better served opening an [issue on the dbt Core repo](https://github.com/dbt-labs/dbt-core/issues) to see whether there is any appetite to make this more customisable.

I haven’t looked into it, but you _might_ also be able to get somewhere with YAML selectors if you haven’t already? They have a bit more control: [YAML Selectors | dbt Developer Hub](https://docs.getdbt.com/reference/node-selection/yaml-selectors)
