Jinja string and bool tests

I am trying to test a variable (is_full_refresh) whether it’s True or False or ‘True’ or ‘False’ and create a conditional model based on that; but cannot get the value of the variable right. Is there something I am missing here?
test referenece:
https://jinja.palletsprojects.com/en/3.1.x/templates/#list-of-builtin-tests

sample code:

{% set is_full_refresh = var("ahoy_is_full_refresh") %}
SELECT {{ is_full_refresh }}, {{ is_full_refresh is string }}, {{ is_full_refresh == 'False' }}, {{ is_full_refresh == 'false' }}, {{ is_full_refresh == 'FALSE' }}, {{ is_full_refresh == 'f' }}, {{ is_full_refresh|as_bool is string }}, {{ is_full_refresh is false }}, {{ is_full_refresh|as_bool is false }}

compiles to

SELECT False, True, False, False, False, False, True, False, False

which is

 {{ is_full_refresh }} -> False
{{ is_full_refresh is string }} -> True
{{ is_full_refresh == 'False' }} -> False
{{ is_full_refresh == 'false' }} -> False
, {{ is_full_refresh == 'FALSE' }} -> False
{{ is_full_refresh == 'f' }} -> False
{{ is_full_refresh|as_bool is string }} -> True
 {{ is_full_refresh is false }} -> False
{{ is_full_refresh|as_bool is false }} -> False

same results with “True”. So what is the value of is_full_refresh?
the variable is defined in dbt_project.yml (ahoy_is_full_refresh: “{{ ahoy_is_full_refresh() }}”)
macro code:

{% macro ahoy_is_full_refresh() %}

    {% set is_full_refresh_hr = run_started_at.strftime("%H") == env_var("DBT_AHOY_FULL_REF_HOUR") %}
    {% set is_full_refresh_enforced = env_var("DBT_AHOY_FULL_REF_ENFORCE")=="true" %}
    {% set is_full_refresh = is_full_refresh_hr or is_full_refresh_enforced %}

    {{ is_full_refresh }}

{% endmacro %}
1 Like

Yes, missing a trim. I had no Idea so many trailing and leading blanks added to vars for no reason.

{{ is_full_refresh|trim == 'False' }} -> True

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