fix: render Jinja blocks before splitting on semicolons (#2650)#2782
Open
sfc-gh-moczko wants to merge 1 commit intomainfrom
Open
fix: render Jinja blocks before splitting on semicolons (#2650)#2782sfc-gh-moczko wants to merge 1 commit intomainfrom
sfc-gh-moczko wants to merge 1 commit intomainfrom
Conversation
`split_statements()` splits SQL on `;` before template rendering,
breaking Jinja block statements (`{% if %}`, `{% for %}`, etc.) that
contain semicolons. This moves Jinja rendering to a pre-render step
on the whole content before splitting, while legacy/standard syntax
continues to render per-statement.
Closes #2650
.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)
Co-Authored-By: Cortex Code <noreply@snowflake.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{% if %},{% for %}, etc.) containing semicolons were broken becausesplit_statements()splits on;before Jinja rendering, producing invalid template fragments.split_statements(), while legacy (&{ }) and standard (<% %>) syntax continues to render per-statement (they are variable-only, no blocks).Root Cause
The SQL execution pipeline called
split_statements()then per-statement template rendering. Sincesplit_statementsis unaware of Jinja block syntax, a query like:was split into two broken fragments:
{% if var == 'Jinja' %}select 1;-- unclosedifblock --> TemplateSyntaxError{% endif %}-- orphanedendif--> TemplateSyntaxErrorFix
Jinja block rendering now happens on the whole content before splitting. The per-statement pipeline still handles legacy/standard variable substitution (which never had block syntax). This is safe because Jinja
{{ }}/{% %}syntax is orthogonal to<% %>/&{ }-- rendering one leaves the other untouched.Changes
statement_reader.pypre_renderparameter toquery_reader()andfiles_reader()manager.pytests/sql/test_sql.pyTest plan