Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
mcasara opened this issue Oct 22, 2024 · 0 comments · May be fixed by #960
Open
1 task done

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

mcasara opened this issue Oct 22, 2024 · 0 comments · May be fixed by #960
Labels
bug Something isn't working triage

Comments

@mcasara
Copy link

mcasara commented Oct 22, 2024

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

@mcasara mcasara added bug Something isn't working triage labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
1 participant