Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

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

Description

@b-per

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageTis issue or pull request must be triaged by a project maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions