Skip to content

Commit

Permalink
Fix #11275: _get_doc_blocks is crashing parsing if .format is cal…
Browse files Browse the repository at this point in the history
…led (#11310)

* Fix #11275: get_doc_blocks is crashing parsing

* Add changie
  • Loading branch information
aranke authored Feb 18, 2025
1 parent 93e2754 commit 2ba765d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20250218-134745.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
45 changes: 45 additions & 0 deletions tests/functional/docs/test_doc_blocks_formatting.py
Original file line number Diff line number Diff line change
@@ -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"] == []

0 comments on commit 2ba765d

Please sign in to comment.