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

fix for spaces and quotes in jinja block matching #208

Merged
merged 2 commits into from
May 21, 2024

Conversation

dave-connors-3
Copy link
Collaborator

closes #205

Some users saw issues when we collected jinja blocks due to a few shortcomings of our regex matching for jinja blocks, namely:

  1. spaces on either side of the start/end lines of the jinja blocks {%docs my_docs %} vs {% docs my_docs %}
  2. special characters in docs names

The fix for problem 1 was fairly straightforward, just updating our space matches to be zero or more. In testing, i also found we were lacking support for default values that included quote characters.

I didn't make any adjustments for special characters, but did add a test for a block name with a special character, and it seemed to pass. Happy to change that if this test is insufficient!

@nicholasyager nicholasyager added the bug Something isn't working label May 9, 2024
Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dave-connors-3 Great turn around time on this! The extensive tests make me feel quite comfortable with this change's ability to fix our users' issues. I left a small non-blocking comment to remove an old regex comment. Otherwise, this looks great!

Comment on lines +133 to +135
def test_from_file_detects_block_range_special_character(self):
range = JinjaBlock.find_block_range(special_character, "docs", "cust-omer_id")
assert range == (2, 73)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to see that the inner dash is still identified correctly!

dbt_meshify/storage/jinja_blocks.py Outdated Show resolved Hide resolved
@@ -24,7 +24,8 @@ def find_block_range(file_content: str, block_type: str, name: str) -> Tuple[int
end_line = None

for match in re.finditer(
r"{%-?\s+" + block_type + r"\s+" + name + r"([(a-zA-Z0-9=,_ )]*)\s-?%}",
r"{%-?\s*" + block_type + r"\s*" + name + r"\s*([(a-zA-Z0-9=,_ \'\")]*)\s*-?%}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call swapping the + for *!

Co-authored-by: Nicholas A. Yager <yager@nicholasyager.com>
@dave-connors-3 dave-connors-3 merged commit 573ebac into main May 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants