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

Iteration issue in get_select_statement_info #2817

Closed
3 tasks done
tunetheweb opened this issue Mar 8, 2022 · 0 comments · Fixed by #2818
Closed
3 tasks done

Iteration issue in get_select_statement_info #2817

tunetheweb opened this issue Mar 8, 2022 · 0 comments · Fixed by #2818
Labels
bug Something isn't working rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors

Comments

@tunetheweb
Copy link
Member

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Run sqlfluff fix -f --dialect bigquer on the following SQL:

SELECT
    gcpproject.functions.timestamp_parsing(log_tbl.orderdate) AS orderdate
FROM
    `gcp-project.data.year_2021` AS log_tbl

Expected Behaviour

It lints and fixes

Observed Behaviour

% sqlfluff fix -f --dialect bigquery test.sql --fixed-suffix FIXED
==== finding fixable violations ====
CRITICAL   [L020] Applying rule L020 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L020.py", line 105, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L025] Applying rule L025 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L025.py", line 67, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L027] Applying rule L027 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L020.py", line 105, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L044] Applying rule L044 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L044.py", line 146, in _eval
    return self._analyze_result_columns(crawler.query_tree)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L044.py", line 92, in _analyze_result_columns
    for wildcard in selectable.get_wildcard_info():
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select_crawler.py", line 84, in get_wildcard_info
    if not self.select_info:
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/functools.py", line 967, in __get__
    val = self.func(instance)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select_crawler.py", line 42, in select_info
    return get_select_statement_info(
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
WARNING    One fix for L016 not applied, it would re-cause the same error.                                                                                                       
CRITICAL   [L020] Applying rule L020 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L020.py", line 105, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L025] Applying rule L025 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L025.py", line 67, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L027] Applying rule L027 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L020.py", line 105, in _eval
    select_info = get_select_statement_info(context.segment, context.dialect)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
CRITICAL   [L044] Applying rule L044 threw an Exception: local variable 'seg' referenced before assignment                                                                       
Traceback (most recent call last):
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/base.py", line 535, in crawl
    res = self._eval(context=context)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L044.py", line 146, in _eval
    return self._analyze_result_columns(crawler.query_tree)
  File "/Users/barry/sqlfluff/src/sqlfluff/rules/L044.py", line 92, in _analyze_result_columns
    for wildcard in selectable.get_wildcard_info():
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select_crawler.py", line 84, in get_wildcard_info
    if not self.select_info:
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/functools.py", line 967, in __get__
    val = self.func(instance)
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select_crawler.py", line 42, in select_info
    return get_select_statement_info(
  File "/Users/barry/sqlfluff/src/sqlfluff/core/rules/analysis/select.py", line 83, in get_select_statement_info
    if seg and any(
UnboundLocalError: local variable 'seg' referenced before assignment
== [test.sql] FAIL                                                                                                                                                               
L:   1 | P:   1 | L036 | Select targets should be on a new line unless there is
                       | only one select target.
L:   4 | P:  37 | L031 | Avoid aliases in from clauses and join conditions.
==== fixing violations ====
2 fixable linting violations found
FORCE MODE: Attempting fixes...
Persisting Changes...
== [test.sql] PASS
Done. Please check your files to confirm.
  [6 unfixable linting violations found]

How to reproduce

As per above

Dialect

Bigquery

Version

0.11.0

Configuration

Default (though note dialect overriden to bigquery above)

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

@tunetheweb tunetheweb added the bug Something isn't working label Mar 8, 2022
@tunetheweb tunetheweb added the rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors label Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant