Skip to content

the expression of jinja has indent bug. #536

Closed
@yassun7010

Description

Describe the bug
There is a bug where if you use a multi-line string to indent an expression in a jinja block, the indentation will increase each time the format is updated.

To Reproduce

The indentation of expressions within blocks in jinja is added each time it is formatted.
Every time you change the select statement and need to reformat it, the indentation increases.

{{
    config(
        materialized="incremental",
        pre_hook="""
                delete from
                    dwh.user as t using (
                    select distinct campaign_name, date
                    from datalake.conversion
                    where date_part = date('{{ execution_date }}')
                ) as s
                where
                    t.campaign_name = s.campaign_name
                    and to_date(t.imported_at) <= s.date_part
                """,
    )
}}

select
    campaign_name,
    date_part,
    count(distinct user_id) as users

Expected behavior
Indentation does not increase after formatting.

{{
    config(
        materialized="incremental",
        pre_hook="""
                delete from
                    dwh.user as t using (
                    select distinct campaign_name, date
                    from datalake.conversion
                    where date_part = date('{{ execution_date }}')
                ) as s
                where
                    t.campaign_name = s.campaign_name
                    and to_date(t.imported_at) <= s.date_part
                """,
    )
}}

select campaign_name, date_part, count(distinct user_id) as users

Actual behavior
Provide any output generated by sqlfmt here. If this is a formatting issue, include the code generated by sqlfmt.

{{
    config(
        materialized="incremental",
        pre_hook="""
                delete from
                    dwh.user as t using (
                    select distinct campaign_name, date
                    from datalake.conversion
                    where date_part = date('{{ execution_date }}')
                ) as s
                where
                    t.campaign_name = s.campaign_name
                    and to_date(t.imported_at) <= s.date_part
                """,
    )
}}

select campaign_name, date_part, count(distinct user_id) as users

Additional context

$ sqlfmt --version
sqlfmt, version 0.21.0
shandy-sqlfmt.mov

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions