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

Make the contents of the raw blocks regex pattern non-greedy (#2241) #2252

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## dbt 0.16.1 (Relase date TBD)


### Fixes
- Fix an issue with raw blocks where multiple raw blocks in the same file resulted in an error ([#2241](https://github.com/fishtown-analytics/dbt/issues/2241), [#2252](https://github.com/fishtown-analytics/dbt/pull/2252))
- Fix a redshift-only issue that caused an error when `dbt seed` found a seed with an entirely empty column that was set to a `varchar` data type. ([#2250](https://github.com/fishtown-analytics/dbt/issues/2250), [#2254](https://github.com/fishtown-analytics/dbt/pull/2254))

### Under the hood
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def end_pat(self):

RAW_BLOCK_PATTERN = regex(''.join((
r'(?:\s*\{\%\-|\{\%)\s*raw\s*(?:\-\%\}\s*|\%\})',
r'(?:.*)',
r'(?:.*?)',
r'(?:\s*\{\%\-|\{\%)\s*endraw\s*(?:\-\%\}\s*|\%\})',
)))

Expand Down
44 changes: 44 additions & 0 deletions test/unit/test_docs_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@
)


MULTIPLE_RAW_BLOCKS = r'''
{% docs some_doc %}
{% raw %}
```
{% docs %}some doc{% enddocs %}
```
{% endraw %}
{% enddocs %}

{% docs other_doc %}
{% raw %}
```
{% docs %}other doc{% enddocs %}
```
{% endraw %}
{% enddocs %}
'''


class DocumentationParserTest(unittest.TestCase):
def setUp(self):
if os.name == 'nt':
Expand Down Expand Up @@ -164,3 +183,28 @@ def test_load_file_extras(self):
self.assertIsInstance(result, ParsedDocumentation)
self.assertEqual(results[0].name, 'snowplow_sessions')
self.assertEqual(results[1].name, 'snowplow_sessions__session_id')

def test_multiple_raw_blocks(self):
parser = docs.DocumentationParser(
results=ParseResult.rpc(),
root_project=self.root_project_config,
project=self.subdir_project_config,
macro_manifest=Manifest.from_macros())

file_block = self._build_file(MULTIPLE_RAW_BLOCKS, 'test_file.md')

parser.parse_file(file_block)
results = sorted(parser.results.docs.values(), key=lambda n: n.name)
self.assertEqual(len(results), 2)
for result in results:
self.assertIsInstance(result, ParsedDocumentation)
self.assertEqual(result.package_name, 'some_package')
self.assertEqual(result.original_file_path, self.testfile_path)
self.assertEqual(result.root_path, self.subdir_path)
self.assertEqual(result.resource_type, NodeType.Documentation)
self.assertEqual(result.path, 'test_file.md')

self.assertEqual(results[0].name, 'other_doc')
self.assertEqual(results[0].block_contents, '```\n {% docs %}other doc{% enddocs %}\n ```')
self.assertEqual(results[1].name, 'some_doc')
self.assertEqual(results[1].block_contents, '```\n {% docs %}some doc{% enddocs %}\n ```', )