question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

L003 behavior different between 0.3.6 and 0.4.0a3

See original GitHub issue

I have a dbt model that looks like the following:

-- TODO: Update this model
with source_data as (
    select * from {{ source('source_name', 'xxx_yyy_zzz') }}   
)

select *
from source_data

Using sqlfluff==0.3.6 (with jinja templater) I get the following lint output:

L:   3 | P:  44 | L001 | Unneccessary trailing whitespace.

Using sqlfluff==0.4.0a3 (with jinja templater) I get the following lint output:

L:   3 | P:  44 | L001 | Unnecessary trailing whitespace.
L:   4 | P:   1 | L003 | Indentation not consistent with line #3
L:   6 | P:   1 | L003 | Indentation not consistent with line #3
L:   7 | P:   1 | L003 | Line under-indented compared to line #3

When I run sqlfluff fix on the file with 0.4.0a3 it tries to fix it to be:

-- TODO: Update this model
with source_data as (
    select * from {{ source('source_name', 'xxx_yyy_zzz') }}

)

    select *
        from source_data

This seems like unexpected behavior to me. The fix suggests that sqlfluff may be misunderstanding the indentation levels of my model.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
alanmcruickshankcommented, Feb 20, 2021

Yep - found the issue. This should be an easy fix - I’ll make a test case to catch it too.

1reaction
barrywhartcommented, Feb 11, 2021

Some thoughts on the previous comment…

My understanding of sqlfluff fix is that it’s doing two things:

  • Applying fixes from those rules that implement fixes. By rules, I mean these.
  • Besides the individual rules, the core of SQLFluff includes an indentation algorithm (described here) which understands SQL syntax and is generally “smart” about indenting things based on the underlying language grammar and some indentation hints embedded in the grammar. This only comes into play when a line is too long. Otherwise, it will leave things on one line.

The latter is the reason ON and AND behave as described.

I agree with the original poster; there definitely seems to be a bug here. I don’t have any intuition at this time about the cause.

A few follow-up questions:

  • Can you provide your .sqlfluff file?
  • I’m curious if you see similar behavior with a similar query that does not involve macros.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vol.136, Nos.1-4 (1995) - DTIC
We have found a different temperature dependence in energy transfer processes involving a small number of phonons. 1 YAG:Er, Ho.
Read more >
Full text of "DTIC AD0747808: An Analytical Evaluation of the ...
Conclusions resulting from this comparison show that the CTR nas the ... The present analysis describes the behavior of articulated rotors with pitch ......
Read more >
vscode-sqlfluff - Coder Social Home
A linter and auto-formatter for SQLFluff, a popular linting tool for SQL and dbt. linter in action. You can run Format Document to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found