When running DBT, my configuration in dbt_project.yml doesn’t work for “dbt_constraints” package correctly.
Based on the documentation given by “dbt_constraints” package maintainers, there’s an argument to turn off dbt constraints completely:
vars:
dbt_constraints_enabled: false
When using it this way as shown above, everything works and the package is not running and creating constraints. However, if I modify it a little bit – I need to have conditional arguments passed, meaning that for DEV env, it’ll be “false” etc. My configuration is as follows: (note that we are using similar configuration for different variables and it works)
vars:
dbt_constraints_enabled: |
{%- if target.name in ['dev_airflow','dev_local'] -%} false
{%- else -%} true
{%- endif -%}
It shouldn’t run only on DEV and DEV LOCAL, all other envs it should run.
I tried multiple ways of formatting the Jinja config – such as having “elif” instead of “else” and specifying all other envs. Then I also tried using lowercase, uppercase, camelcase.
I even created dbt model, that would check the variable current state, since I didn’t know how to print var inside of Jinja. It was shown correctly in the model and constraints still ran. I’ve spent almost 10-15 hours trying to somehow get it to work but unsuccessfully.
Any help will be greatly appreciated.