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

JinjaTracer fix for endif/endfor inside "set" or "macro" blocks #2868

Merged
merged 1 commit into from Mar 15, 2022

Conversation

barrywhart
Copy link
Member

@barrywhart barrywhart commented Mar 15, 2022

Brief summary of the change made

This is a follow-up for issue #2835: The issue recurred after fixing issue #2822.

Fixes a bug I introduced in PR #2862. In adding tracing for {% endif %} and {% endfor %}, I neglected to consider that these can occur inside "set" or "macro" blocks. In those cases, we don't wait to trace them because we consider those regions to be templated code, and "jumping" there throws off the trace.

This PR simply adds a guard to avoid tracing if we're inside a "set" or "macro" block.

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

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.

@barrywhart barrywhart marked this pull request as draft March 15, 2022 15:51
@barrywhart barrywhart marked this pull request as ready for review March 15, 2022 15:58
@barrywhart barrywhart changed the title Follow-up for issue 2835: The issue recurred after fixing issue 2822 JinjaTracer fix for endif/endfor inside "set" or "macro" blocks Mar 15, 2022
"endif",
elif (
block_type == "block_end"
and set_idx is 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.

This line is the code I added. The rest is just Black reformatting the existing code.

@@ -910,12 +910,52 @@ def test__templater_jinja_slice_template(test, result):
("block_start", slice(0, 32, None), slice(0, 0, None)),
("literal", slice(32, 37, None), slice(0, 0, None)),
("block_start", slice(37, 62, None), slice(0, 0, None)),
("literal", slice(62, 67, None), slice(0, 0, 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.

Updating the expected test results for the previously added test. I manually reviewed these and confirmed that the old results were incorrect.

raw_file, templated_file, make_template=make_template
)
# Create a TemplatedFile from the results. This runs some useful sanity
# checks.
_ = TemplatedFile(raw_file, "<<DUMMY>>", templated_str, sliced_file, raw_sliced)
Copy link
Member Author

Choose a reason for hiding this comment

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

This added line runs the same sanity check we use in production and will help avoid introducing any future "bad" test results.

@codecov
Copy link

codecov bot commented Mar 15, 2022

Codecov Report

Merging #2868 (6d74083) into main (f6f6c2f) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #2868   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          163       163           
  Lines        12458     12458           
=========================================
  Hits         12458     12458           
Impacted Files Coverage Δ
src/sqlfluff/core/templaters/slicers/tracer.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 f6f6c2f...6d74083. Read the comment docs.

@tunetheweb tunetheweb merged commit 613d588 into sqlfluff:main Mar 15, 2022
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.

None yet

2 participants