Skip to content

Commit 1933af5

Browse files
Fixes #27792: Read dbt test descriptions from config.meta and patch on re-ingestion
- Add _get_dbt_test_description() helper that resolves description from node.description (schema.yml) with fallback to node.config.meta["description"] (config() block in SQL file) - Patch TestDefinition and TestCase descriptions on re-ingestion when dbtUpdateDescriptions is enabled - Add 19 unit tests covering both fixes
1 parent f9eb03b commit 1933af5

2 files changed

Lines changed: 475 additions & 2 deletions

File tree

ingestion/src/metadata/ingestion/source/database/dbt/metadata.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@
114114
logger = ingestion_logger()
115115

116116

117+
def _get_dbt_test_description(manifest_node) -> Optional[str]: # noqa: UP045
118+
"""Get test description, falling back to config.meta.description.
119+
120+
dbt tests can carry descriptions in two places inside manifest.json:
121+
1. ``node.description`` — set via the ``description:`` key in schema.yml
122+
2. ``node.config.meta.description`` — set via ``config(meta={'description': ...})``
123+
inside the test SQL file.
124+
125+
OpenMetadata historically only reads path (1). This helper also checks
126+
path (2) so that tests documented through the ``config()`` block are
127+
picked up as well.
128+
"""
129+
if manifest_node.description:
130+
return manifest_node.description
131+
if (
132+
hasattr(manifest_node, "config")
133+
and manifest_node.config
134+
and hasattr(manifest_node.config, "meta")
135+
and isinstance(manifest_node.config.meta, dict)
136+
):
137+
return manifest_node.config.meta.get("description") or None
138+
return None
139+
140+
117141
class InvalidServiceException(Exception): # noqa: N818
118142
"""
119143
The service passed in config is not found
@@ -1405,21 +1429,29 @@ def create_dbt_tests_definition(self, dbt_test: dict) -> Iterable[Either[CreateT
14051429
fqn=manifest_node.name,
14061430
entity=TestDefinition,
14071431
)
1432+
description = _get_dbt_test_description(manifest_node)
14081433
if not check_test_definition_exists:
14091434
entity_type = EntityType.TABLE
14101435
if get_manifest_column_name(manifest_node):
14111436
entity_type = EntityType.COLUMN
14121437
yield Either(
14131438
right=CreateTestDefinitionRequest(
14141439
name=manifest_node.name,
1415-
description=manifest_node.description,
1440+
description=description,
14161441
entityType=entity_type,
14171442
testPlatforms=[TestPlatform.dbt],
14181443
parameterDefinition=create_test_case_parameter_definitions(manifest_node),
14191444
displayName=None,
14201445
owners=None,
14211446
)
14221447
)
1448+
elif description and self.source_config.dbtUpdateDescriptions:
1449+
self.metadata.patch_description(
1450+
entity=TestDefinition,
1451+
source=check_test_definition_exists,
1452+
description=description,
1453+
force=True,
1454+
)
14231455
except Exception as err: # pylint: disable=broad-except
14241456
yield Either(
14251457
left=StackTraceError(
@@ -1454,19 +1486,27 @@ def create_dbt_test_case(self, dbt_test: dict) -> Iterable[Either[CreateTestCase
14541486
)
14551487

14561488
test_case = self.metadata.get_by_name(TestCase, test_case_fqn, fields=["testDefinition,testSuite"])
1489+
description = _get_dbt_test_description(manifest_node)
14571490
if test_case is None:
14581491
# Create the test case only if it does not exist
14591492
yield Either(
14601493
right=CreateTestCaseRequest(
14611494
name=manifest_node.name,
1462-
description=manifest_node.description,
1495+
description=description,
14631496
testDefinition=FullyQualifiedEntityName(manifest_node.name),
14641497
entityLink=entity_link_str,
14651498
parameterValues=create_test_case_parameter_values(dbt_test),
14661499
displayName=None,
14671500
owners=None,
14681501
)
14691502
)
1503+
elif description and self.source_config.dbtUpdateDescriptions:
1504+
self.metadata.patch_description(
1505+
entity=TestCase,
1506+
source=test_case,
1507+
description=description,
1508+
force=True,
1509+
)
14701510
logger.debug(f"Test case Already Exists: {test_case_fqn}")
14711511
except Exception as err: # pylint: disable=broad-except
14721512
yield Either(

0 commit comments

Comments
 (0)