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

Prevent exceptions when running fix on dialect fixtures #2818

Conversation

tunetheweb
Copy link
Member

@tunetheweb tunetheweb commented Mar 8, 2022

Brief summary of the change made

Fixes #2817 with simple additional safeguard test.
Fixes #2812
Also adds a few more I've found in similar cases.
And updates our CI to test fix instead of lint against dialect fixtures (not fix does a lint as part of that so lint is still tested), to prevent similar future issues.

Are there any other side effects of this change that we should be aware of?

The fix tests take longer to run, finishing just after windows tests (which was previous slowest test) so CI does slow down a couple of mins :-(

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #2818 (e822b79) into main (8bcd099) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2818   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          163       163           
  Lines        12322     12326    +4     
=========================================
+ Hits         12322     12326    +4     
Impacted Files Coverage Δ
src/sqlfluff/core/rules/analysis/select.py 100.00% <100.00%> (ø)
src/sqlfluff/core/rules/base.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L026.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L028.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bcd099...e822b79. Read the comment docs.

@tunetheweb tunetheweb changed the title Prevent iteration error in get_select_statement_info Prevent exceptions when running fix on dialect fixtures Mar 8, 2022
@WittierDinosaur
Copy link
Contributor

can we add test cases for the things it fixes?

@tunetheweb
Copy link
Member Author

can we add test cases for the things it fixes?

Yeah probably should. This started out as one simple fix, but growing legs as I scan the rest of the dialect fixtures. Will start to add some test cases.

src/sqlfluff/core/rules/base.py Outdated Show resolved Hide resolved
src/sqlfluff/rules/L026.py Show resolved Hide resolved
@tunetheweb
Copy link
Member Author

can we add test cases for the things it fixes?

Added where possible. Through two I couldn't get to work under pytest.

@@ -802,28 +802,32 @@ def _choose_anchor_segment(

anchor: BaseSegment = segment
child: BaseSegment = segment
for seg in context.parent_stack[0].path_to(segment)[1:-1][::-1]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this bit hiding whitespace:

image

Comment on lines -131 to 132
assert len(table_aliases) > 0, "Only Selects with tables should be checked"
if len(table_aliases) > 1:
if len(table_aliases) != 1:
return None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see why we abort on more than one, but not on 0? Same thing IMHO and this fixes one of the issues raised.

@tunetheweb
Copy link
Member Author

This should be good to go now. Includes the lint->fix script update.

See note about, about timing though :-( But only a minute or so slower and I think worth it.

src/sqlfluff/rules/L026.py Outdated Show resolved Hide resolved
src/sqlfluff/rules/L026.py Outdated Show resolved Hide resolved
Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I asked about whether/when we want to do the sqlfluff fix test using other .sqlfluff configurations. (Danny's configuration seemed to produce a lot more errors than the default.)

for DIALECT in "${DIALECTS[@]}"
do
echo "Testing $DIALECT SQL files fix without critical errors..."
OUTPUT=$(sqlfluff fix -f ${DIALECT})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interested in adding other .sqlfluff files, e.g. Danny's from #2811? (Feel free to create a ticket for later.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already the longest running job so would suggest a separate, parallel, job if we do that.

However I did test it with tab_space = 2 and got no CRITICAL errors (which is all it currently looks for) any more since your fix, plus the ones here.

Are you still getting the errors if you do it on this branch? Cause if not, then no need to add. The default config identified the issues and they were fixed.

@tunetheweb tunetheweb merged commit 36b79bd into sqlfluff:main Mar 9, 2022
@tunetheweb tunetheweb deleted the prevent-itteration-error-in-get_select_statement_info branch March 9, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iteration issue in get_select_statement_info Critical Bug - Python Exception During SQLFluff fix
3 participants