Skip to content

Commit

Permalink
Expand doc_blocks backcompat test
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Feb 11, 2025
1 parent fc8137c commit 46b533a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/dbt/artifacts/resources/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ class ColumnInfo(AdditionalPropertiesMixin, ExtensibleDbtClassMixin):
granularity: Optional[TimeGranularity] = None
doc_blocks: List[str] = field(default_factory=list)

def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None) -> dict:
dct = super().__post_serialize__(dct, context)

# Remove doc_blocks from output if they are not a list of strings
if isinstance(dct["doc_blocks"], list):
if not all(isinstance(x, str) for x in dct["doc_blocks"]):
dct["doc_blocks"] = []
else:
dct["doc_blocks"] = []

return dct


@dataclass
class InjectedCTE(dbtClassMixin):
Expand Down Expand Up @@ -202,10 +214,19 @@ class ParsedResource(ParsedResourceMandatory):

def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None):
dct = super().__post_serialize__(dct, context)

if context and context.get("artifact") and "config_call_dict" in dct:
del dct["config_call_dict"]
if context and context.get("artifact") and "unrendered_config_call_dict" in dct:
del dct["unrendered_config_call_dict"]

# Remove doc_blocks from output if they are not a list of strings
if isinstance(dct["doc_blocks"], list):
if not all(isinstance(x, str) for x in dct["doc_blocks"]):
dct["doc_blocks"] = []

Check warning on line 226 in core/dbt/artifacts/resources/v1/components.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/resources/v1/components.py#L226

Added line #L226 was not covered by tests
else:
dct["doc_blocks"] = []

Check warning on line 228 in core/dbt/artifacts/resources/v1/components.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/artifacts/resources/v1/components.py#L228

Added line #L228 was not covered by tests

return dct


Expand Down
38 changes: 38 additions & 0 deletions tests/functional/docs/test_doc_blocks_backcompat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
import os

import pytest

from dbt.tests.util import run_dbt

schema_yml = """
models:
- name: my_colors
doc_blocks: 2
columns:
- name: id
doc_blocks: 2
- name: color
doc_blocks: ["hello", 2, "world"]
"""


class TestDocBlocksBackCompat:
@pytest.fixture(scope="class")
def models(self):
return {
"my_colors.sql": "select 1 as id, 'blue' as color",
"schema.yml": schema_yml,
}

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"]
assert model_data["doc_blocks"] == []
assert all(column["doc_blocks"] == [] for column in model_data["columns"].values())

0 comments on commit 46b533a

Please sign in to comment.