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 #11275: _get_doc_blocks is crashing parsing if .format is called #11310

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] == []
Loading