Skip to content

Commit

Permalink
Fix static parser tracking logic (dbt-labs#4332)
Browse files Browse the repository at this point in the history
* Fix static parser tracking logic

* Add changelog note
  • Loading branch information
jtcohen6 authored Nov 24, 2021
1 parent d046ae0 commit 7f2d3cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Under the hood
- Change some CompilationExceptions to ParsingExceptions ([#4254](http://github.com/dbt-labs/dbt-core/issues/4254), [#4328](https://github.com/dbt-core/pull/4328))
- Reorder logic for static parser sampling to speed up model parsing ([#4332](https://github.com/dbt-labs/dbt-core/pull/4332))


## dbt-core 1.0.0rc2 (November 22, 2021)
Expand Down
24 changes: 14 additions & 10 deletions core/dbt/parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def render_update(
# not when the experimental parser flag is on.
exp_sample: bool = False
# sampling the stable static parser against jinja is significantly
# more expensive and therefor done far less frequently.
# more expensive and therefore done far less frequently.
stable_sample: bool = False
# there are two samples above, and it is perfectly fine if both happen
# at the same time. If that happens, the experimental parser, stable
Expand Down Expand Up @@ -148,20 +148,24 @@ def render_update(
)

self.manifest._parsing_info.static_analysis_parsed_path_count += 1
# if the static parser failed, add the correct messages for tracking
elif isinstance(statically_parsed, str):
if statically_parsed == "cannot_parse":
result += ["01_stable_parser_cannot_parse"]
elif statically_parsed == "has_banned_macro":
result += ["08_has_banned_macro"]

super().render_update(node, config)
fire_event(StaticParserFallbackJinjaRendering(path=node.path))
# if the static parser didn't succeed, fall back to jinja
else:
# jinja rendering
super().render_update(node, config)
fire_event(StaticParserFallbackJinjaRendering(path=node.path))

# if sampling, add the correct messages for tracking
if exp_sample and isinstance(experimental_sample, str):
if experimental_sample == "cannot_parse":
result += ["01_experimental_parser_cannot_parse"]
elif experimental_sample == "has_banned_macro":
result += ["08_has_banned_macro"]
elif stable_sample and isinstance(statically_parsed, str):
if statically_parsed == "cannot_parse":
result += ["81_stable_parser_cannot_parse"]
elif statically_parsed == "has_banned_macro":
result += ["88_has_banned_macro"]

# only send the tracking event if there is at least one result code
if result:
# fire a tracking event. this fires one event for every sample
Expand Down

0 comments on commit 7f2d3cd

Please sign in to comment.