-
-
Notifications
You must be signed in to change notification settings - Fork 651
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
TSQL linting fix: L019+L034 breaks the code #1734
Comments
Note: The output SQL is broken because it's missing the comma after |
And there's a comma after CaseOutput, which breaks the SQL for TSQL at least. |
I did some preliminary investigation. I think L034 is running after L019's edits have already been applied, so when it attempts to reorder the columns, it's inadvertently moving the updated commas as well. You see see this in the L034 "edit" actions below. If I run L034 by itself (with L019 disabled), commas are not included in the edits.
To fix this, we first need to determine where the bug is (and this could be a bit of a philosophical question):
|
I reproduced this bug in the ANSI dialect, so it's not specific to TSQL:
becomes
|
It also happens if I replace the
becomes
Not surprising, but I wanted to verify it happened with a syntactically simpler expression (function call vs |
The bug is in L019. That rule appears to be literally editing the raw content of the For example, here's the ID column as L034 sees it (L019 has already run). Note the comma.
If I run L034 with L019 disabled, the
Instead, the commas are "siblings" of the
|
Correction: L019 is creating a new
This happens in This is similar to other subtle bugs we've seen previously: a rule makes a change that looks correct if you simply render the raw segment strings, but they "corrupt" the parse tree, leaving it in a state that is not possible or correct with respect to the dialect. Ideally, SQLFluff would detect this and either flag it as an internal error (rule bug) or find a way to "make it right", i.e. find another way of applying the edit that respects the dialect. See #1304 for more detail. @alanmcruickshank: FYI. For now, I'll try and fix this by changing L019, as described above. We may end up needing to make this deeper enhancement at some point -- it's not yet clear to me. |
The following code breaks when fixed:
Expected Behaviour
Workable code.
Observed Behaviour
Steps to Reproduce
Run fix on the above
Dialect
TSQL
Version
Include the output of
sqlfluff --version
along with your Python versionmost recent main
Python 3.9.7
Configuration
The text was updated successfully, but these errors were encountered: