Skip to content

dbt_utils.star: Remove trailing whitespace in the comment when no column is returned #959

@mcasara

Description

@mcasara

Describe the bug

When the macro dbt_utils.star uses a non-existing model, the output of the compilation is:

*
/* No columns were returned. Maybe the relation doesn't exist yet 
or all columns were excluded. This star is only output during  
dbt compile, and exists to keep SQLFluff happy. */

Notice the trailing whitespaces yet , during , which fail sqlfluff's linting with L001 Unnecessary trailing whitespace.

While there, use {%- ... -%} instead of {% ... %} in the macro statements to remove trailing whitespaces.

Steps to reproduce

Compile a non existing table:

SELECT
  {{ dbt_utils.star(from=ref('non_existing_table')) }}
FROM {{ ref('non_existing_table') }}

which returns:

SELECT
  
*
/* No columns were returned. Maybe the relation doesn't exist yet 
or all columns were excluded. This star is only output during  
dbt compile, and exists to keep SQLFluff happy. */
            
FROM non_existing_table

Expected results

SELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM non_existing_table

Actual results

SELECT
  <- 1 whitespace
*
/* No columns were returned. Maybe the relation doesn't exist yet <- 1 whitespace
or all columns were excluded. This star is only output during  <- 2 whitespaces
dbt compile, and exists to keep SQLFluff happy. */
            <- 12 whitespaces
FROM non_existing_table

Which database are you using dbt with?

  • snowflake

The output of dbt --version:

Core:
  - installed: 1.8.3

Additional context

We lint our compiled dbt models. When a model doesn't exist in one of our database, it compiles with the message that contains whitespaces and fails with sqlfluff's L001 Unnecessary trailing whitespace.

Are you interested in contributing the fix?

Tested in local. I will open a Pull Request

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions