diff --git a/.changes/unreleased/Fixes-20250218-134745.yaml b/.changes/unreleased/Fixes-20250218-134745.yaml new file mode 100644 index 00000000000..c048f5a76a7 --- /dev/null +++ b/.changes/unreleased/Fixes-20250218-134745.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: _get_doc_blocks is crashing parsing if .format is called +time: 2025-02-18T13:47:45.659731Z +custom: + Author: aranke + Issue: "11310" diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 627ad034c2f..0eeef19fb73 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -1672,6 +1672,7 @@ def _get_doc_blocks(description: str, manifest: Manifest, node_package: str) -> isinstance(node, Call) and hasattr(node, "node") and hasattr(node, "args") + and hasattr(node.node, "name") and node.node.name == "doc" ): doc_args = [arg.value for arg in node.args] diff --git a/tests/functional/docs/test_doc_blocks_formatting.py b/tests/functional/docs/test_doc_blocks_formatting.py new file mode 100644 index 00000000000..18aede7127c --- /dev/null +++ b/tests/functional/docs/test_doc_blocks_formatting.py @@ -0,0 +1,45 @@ +import json +import os + +import pytest + +from dbt.tests.util import run_dbt + +docs_md = """{% docs test_doc %} +This is a test for column {test_name} +{% enddocs %} +""" + +schema_yml = """ +models: + - name: my_colors + columns: + - name: id + description: "{{ doc('test_doc').format(test_name = 'id') }}" + - name: color + description: "{{ 'This is a test for column {test_name}'.format(test_name = 'color') }}" +""" + + +class TestDocBlocksBackCompat: + @pytest.fixture(scope="class") + def models(self): + return { + "my_colors.sql": "select 1 as id, 'blue' as color", + "schema.yml": schema_yml, + "docs.md": docs_md, + } + + def test_doc_blocks_back_compat(self, project): + run_dbt(["parse"]) + + assert os.path.exists("./target/manifest.json") + + with open("./target/manifest.json") as fp: + manifest = json.load(fp) + + model_data = manifest["nodes"]["model.test.my_colors"] + + for column_name, column in model_data["columns"].items(): + assert column["description"] == f"This is a test for column {column_name}" + assert column["doc_blocks"] == []