Snowflake-Labs / dbt_constraints

This package generates database constraints based on the tests in a dbt project
Apache License 2.0
138 stars 27 forks source link

Conditional argument not accepted for dbt_constraints_enabled var #69

Open Jaxsss opened 2 months ago

Jaxsss commented 2 months ago

When we want to use conditional logic for dbt_constraints_enabled var it simply doesn't work.

When used the classic way, it works eg. vars: dbt_constraints_enabled: true (or false)

But when I pass some conditions, it doesn't work - it gets build just like if dbt_constraints were enabled (true)

This is my config: vars: dbt_constraints_enabled: {%- if target.name in ['dev_airflow','dev_local'] -%} false {%- else -%} true {%- endif -%}

I tried it on different projects (also clean version of jaffle_shop from dbt) but it didn't help, I started thinking it's not the issue of the config and conditional if else statement, but the package itself, I'd be glad if you could look into it.

I'm also including Stackoverflow question for more context.

sfc-gh-dflippo commented 1 month ago

I'm relying on dbt core's features for how values are set for variables so I don't think it is any of my code. However, you might want to try setting it a slightly different way using a conditional expression:

vars:
  dbt_constraints_enabled: "{{ 'true' if target.name in ['dev_airflow','dev_local'] else 'false' }}"