-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
Fix runtime error (IndexError ) when linting file with jinja "if" #1430
Fix runtime error (IndexError ) when linting file with jinja "if" #1430
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1430 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 127 129 +2
Lines 8639 8709 +70
=========================================
+ Hits 8639 8709 +70
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting some changes below.
However think there is more going on as discovered some other oddness when testing multiple for
loops in the same file.
For example this fails with an L016 exception:
-- This file combines product data from individual brands into a staging table
{% set products = [
'table1',
'table2'] %}
{% for product in products %}
SELECT
brand,
country_code,
category,
name,
id
FROM
{{ product }};
{% endfor %}
{% for product in products %}
SELECT
brand,
country_code,
category,
name,
id
FROM
{{ product }};
{% endfor %}
Seems to be unrelated to your change (it's broken with main
code, with your suggested changes, and also with my suggested further changes to your change) so maybe raise a separate issue for this one?
test/fixtures/linter/autofix/ansi/016_index_error_with_jinja_if/after.sql
Outdated
Show resolved
Hide resolved
test/fixtures/linter/autofix/ansi/016_index_error_with_jinja_if/after.sql
Show resolved
Hide resolved
test/fixtures/linter/autofix/ansi/016_index_error_with_jinja_if/before.sql
Outdated
Show resolved
Hide resolved
name, | ||
id | ||
FROM | ||
{{ product }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong and shouldn't dedent. But not sure why it does. Any ideas @barrywhart ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know exactly, but I do know that SQLFluff is conservative about applying fixes in or near templated areas (i.e. curly braces). Probably related to that. Want to create another issue for that? I'm happy to keep working on these, but trying to avoid letting any single issue become too much of a 🐇 hole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed just now that it indents correctly when run on a post-expansion version of the file, i.e.:
-- This file combines product data from individual brands into a staging table
SELECT
brand,
country_code,
category,
name,
id
FROM
table1
UNION ALL
SELECT
brand,
country_code,
category,
name,
id
FROM
table2
I'll create an issue for the other thing you found. I thought possibly my other PR (#1431) may help with that, but it didn't. |
Created issue #1433. I think this PR is ready for another review. Want me to also create an issue for the indentation thing with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this if you are @barrywhart . Gave it a thorough review earlier and suggested changes which have been applied.
As discussed, investigations have thrown up another few related issues, but they didn't work previously either and this seems a good improvement.
Brief summary of the change made
Fixes #1414
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 intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/parser
(note YML files can be auto generated withpython test/generate_parse_fixture_yml.py
or by runningtox
locally).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.