Skip to content

[Feature] Support dbt 'is_incremental' in pytest-dbt-core #24

@danaeder

Description

@danaeder

Is this your first time opening an issue?

Describe the Feature

dbt adds the 'this' somehow in the is_incremental macro:
https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql
is_incremental.sql

{% macro is_incremental() %}
{#-- do not run introspective queries in parsing #}
{% if not execute %}
{{ return(False) }}

Describe alternatives you've considered

I would like to test the following macro that uses 'is_incremental' and 'this' argument

{% macro get_table_max_id(where_clause = '', id_column = '"id"') %}
    {% if is_incremental() %}
        {% set max_id_query %}
        select coalesce(max({{ id_column }}), 0) from {{ this }}
        {{ where_clause }}
        {% endset %}
        {% set max_id_res = run_query(max_id_query) %}
    {%endif%}
    {{ return(max_id) }}
{% endmacro %}

following error:
def raise_compiler_error(msg, node=None) -> NoReturn:

  raise CompilationException(msg, node)

E dbt.exceptions.CompilationException: Compilation Error in macro is_incremental (macros/materializations/models/incremental/is_incremental.sql)
E 'this' is undefined
E
E > in macro get_table_max_id (macros/unioner.sql)
E > called by macro test_table_max_id (macros/test_macro.sql)
E > called by macro is_incremental (macros/materializations/models/incremental/is_incremental.sql)

Who will this benefit?

All dbt users since is_incremental is very popular

Are you interested in contributing this feature?

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions