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

sqlfluff crashes when formatting tsql code that contains keyworded columns #5828

Open
3 tasks done
stevewgr opened this issue Apr 29, 2024 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect

Comments

@stevewgr
Copy link

stevewgr commented Apr 29, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

sqlfluff crashes when formatting tsql code that contains keyworded columns.

See related ticket: #3852

Expected Behaviour

Should format properly.

Observed Behaviour

If I add square brackets around the keyworded columns, such as Class, then it formats the below script properly:

ALTER PROCEDURE [dbo].[LOAD_USER_DATA]
  @nRet smallint
AS

SELECT
  Nation, Race, Class, HairColor,
  Hp, Mp, Sp, Strong, Sta, Dex, Intel, Cha, Authority, Points, Gold, Bind, PX, PZ, PY, dwTime, strSkill, strItem,strSerial
FROM USERDATA

GO

How to reproduce

  • Same issue appears to happen with all version. I tried both compile latest from source and also the one installed from pip official package 2.3.5.
  • Create the above script
  • run sqlfluff format
  • observe the crash (logs below)
  • wrap the Class column with square brackets [Class]
  • run format again and see that now it works

Crash logs:

> sqlfluff format .\src\migration\6_alter_load_user_data_procedure.sql
==== finding fixable violations ====
WARNING    Fixes for LT01 not applied, as it would result in an unparsable file. Please report this as a bug with a minimal query which demonstrates this warning. 
WARNING    Fixes for LT02 not applied, as it would result in an unparsable file. Please report this as a bug with a minimal query which demonstrates this warning. 
WARNING    Unable to lint src\migration\6_alter_load_user_data_procedure.sql due to an internal error. Please report this as an issue with your query's contents and stacktrace below!
To hide this warning, add the failing file to .sqlfluffignore
Traceback (most recent call last):
  File "***\lib\site-packages\sqlfluff\core\linter\runner.py", line 109, in run
    yield partial()
  File "***\lib\site-packages\sqlfluff\core\linter\linter.py", line 686, in lint_rendered
    encoding=rendered.encoding,
  File "***\lib\site-packages\sqlfluff\core\linter\linter.py", line 608, in lint_parsed
    formatter=formatter,
  File "***\lib\site-packages\sqlfluff\core\linter\linter.py", line 459, in lint_fix_parsed
    config=config,
  File "***\lib\site-packages\sqlfluff\core\rules\base.py", line 560, in crawl
    self._adjust_anchors_for_fixes(context, elem)
  File "***\lib\site-packages\sqlfluff\core\rules\base.py", line 750, in _adjust_anchors_for_fixes
    fix.anchor,
  File "***\lib\site-packages\sqlfluff\core\rules\base.py", line 782, in _choose_anchor_segment
    assert path, f"No path found from {root_segment} to {segment}!"
AssertionError: No path found from <FileSegment: ([L:  1, P:  1])> to <WordSegment: ([L:  7, P:114]) 'strSerial'>!

Dialect

tsql

Version

2.3.5 and latest from main branch.

Configuration

default

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@stevewgr stevewgr added the bug Something isn't working label Apr 29, 2024
@github-actions github-actions bot added the t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect label Apr 29, 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 t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect
Projects
None yet
Development

No branches or pull requests

1 participant