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

Various issues returning Exception: Unable to find a macro block with the name abcdef. #210

Open
b-per opened this issue May 29, 2024 · 0 comments
Labels
bug Something isn't working triage Tis issue or pull request must be triaged by a project maintainer

Comments

@b-per
Copy link
Contributor

b-per commented May 29, 2024

Describe the bug

Tested with dbt-meshify==0.5.3 as 0.5.4 seems to be broken, at least on my machine.

Running dbt-meshify split reference_data --select "group:xyz" -r returns the error Exception: Unable to find a macro block with the name abcdef. when the macro abcdef is actually in the file

Steps to reproduce

Use case 1

Create a macro with the following code

{% macro abcdef (
   param1 = '', 
   param2 = [],
  param3 = {}
) %}
 -- nothing to seee
{% endmacro %}

The regex here doesn't "find" the macro.

Use case 2

Create a generic test like this

{% test my_test(model,) %}
-- nothing interesting
{% endtest %}

The same piece of code searches the file forblock_type = "macro" and name = "test_my_test", so it raises an Exception as well.

Suggestion

Here, replace

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

by

        if block_type == "macro":
            block_type_new = "(macro|test)"
            name_new = f"({name}|{name[5:]})"
        else:
            block_type_new = block_type
            name_new = name

        pattern = r"{%-?[\s\n]+" + block_type_new + r"[\s\n]+" + name_new + r"([(a-zA-Z0-9=,_ \[\]{}'\s\n)]*)[\s\n]*-?%}" 
        for match in re.finditer(
            pattern,
            file_content,
            re.MULTILINE,
        ):

The handling of test/macro is ugly and should be done better, but at least, on the dbt project I am testing, it works!

@b-per b-per added bug Something isn't working triage Tis issue or pull request must be triaged by a project maintainer labels May 29, 2024
This was referenced May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Tis issue or pull request must be triaged by a project maintainer
Projects
None yet
Development

No branches or pull requests

1 participant