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

Unexpected exception (with no detail) from linting a simple select into a variable #5993

Open
2 of 3 tasks
medianick opened this issue Jul 1, 2024 · 2 comments
Open
2 of 3 tasks
Labels
bug Something isn't working

Comments

@medianick
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I'm linting a T-SQL script (for SQL Server) and received the following:

L:  13 | P:   1 | AL09 | Unexpected exception: ;
Could you open an issue at
                       | https://github.com/sqlfluff/sqlfluff/issues ?

The line in question is as follows:

SELECT @CURRENT_SCHEMA_VERSION = [Version] FROM [HangFire].[Schema];

Expected Behaviour

This line should not have any linting issues given the current configuration and dialect.

Observed Behaviour

An empty exception is raised.

How to reproduce

sqlfluff lint Script.sql

Dialect

tsql

Version

3.0.7

Configuration

[sqlfluff]
dialect = tsql
exclude_rules = LT01,LT05,LT12

[sqlfluff:rules:references.quoting]
prefer_quoted_identifiers = True

[sqlfluff:rules:references.special_chars]
allow_space_in_identifier = True
additional_allowed_characters = .

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

@medianick medianick added the bug Something isn't working label Jul 1, 2024
@medianick
Copy link
Author

Adding the suggested -- noqa: AL09 on the problematic line results in this:

CRITICAL   [AL09] Applying rule AL09 to 'Redacted/Script.sql' threw an Exception:
Traceback (most recent call last):
  File "/app/.venv/lib/python3.9/site-packages/sqlfluff/core/rules/base.py", line 507, in crawl
    res = self._eval(context=context)
  File "/app/.venv/lib/python3.9/site-packages/sqlfluff/rules/aliasing/AL09.py", line 99, in _eval
    assert whitespace and column_identifier and alias_identifier
AssertionError

So, this is a blocker for linting.

@medianick
Copy link
Author

Looking over the code in https://github.com/sqlfluff/sqlfluff/blob/main/src/sqlfluff/rules/aliasing/AL09.py, it appears that this line is being incorrectly detected as containing a column alias (e.g., select col1 as al1) when in fact it's assigning a column into a variable. I expect this is due to SQL Server (and SQLFluff by extension) supporting the old SELECT 'Foo' = Bar syntax for column aliases (see https://www.red-gate.com/hub/product-learning/sql-prompt/sql-prompt-code-analysis-avoid-non-standard-column-aliases). It would be good to allow that to be opted out of or into via configuration switch, or to adjust the alias detection so that this is correctly detected as the variable assignment it is, rather than a column alias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant