Skip to content

Commit

Permalink
include top-level raw/comment blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Mar 25, 2019
1 parent fc1b4ce commit 0a9ed99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/dbt/clients/_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,15 @@ def find_block(self):

# comments are easy
if matchgroups.get('comment_start') is not None:
start = match.start()
self.expect_comment_end()
self.blocks.append(BlockData(self.data[start:self.pos]))
return True

if matchgroups.get('block_type_name') == 'raw':
start = match.start()
self.expect_raw_end()
self.blocks.append(BlockData(self.data[start:self.pos]))
return True

if matchgroups.get('block_type_name') == 'materialization':
Expand Down
24 changes: 24 additions & 0 deletions test/integration/042_sources_test/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,30 @@ def test_run(self):
table={'column_names': ['id'], 'rows': [[2.0]]}
)

macro_with_raw_statement = self.query(
'run',
'{% raw %}select 1 as{% endraw %}{{ test_macros() }}{% macro test_macros() %} id{% endmacro %}',
name='foo'
).json()
self.assertSuccessfulRunResult(
macro_with_raw_statement,
'{% raw %}select 1 as{% endraw %}{{ test_macros() }}',
compiled_sql='select 1 as id',
table={'column_names': ['id'], 'rows': [[1.0]]}
)

macro_with_comment = self.query(
'run',
'{% raw %}select 1 {% endraw %}{{ test_macros() }} {# my comment #}{% macro test_macros() -%} as{% endmacro %} id{# another comment #}',
name='foo'
).json()
self.assertSuccessfulRunResult(
macro_with_comment,
'{% raw %}select 1 {% endraw %}{{ test_macros() }} {# my comment #} id{# another comment #}',
compiled_sql='select 1 as id',
table={'column_names': ['id'], 'rows': [[1.0]]}
)

@use_profile('postgres')
def test_invalid_requests(self):
data = self.query(
Expand Down

0 comments on commit 0a9ed99

Please sign in to comment.