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
JinjaTracer fix for endif/endfor inside "set" or "macro" blocks #2868
Conversation
"endif", | ||
elif ( | ||
block_type == "block_end" | ||
and set_idx is None |
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 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)), |
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.
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) |
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 added line runs the same sanity check we use in production and will help avoid introducing any future "bad" test results.
Codecov Report
@@ Coverage Diff @@
## main #2868 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 163 163
Lines 12458 12458
=========================================
Hits 12458 12458
Continue to review full report at Codecov.
|
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 intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.