|
114 | 114 | logger = ingestion_logger() |
115 | 115 |
|
116 | 116 |
|
| 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 | + |
117 | 141 | class InvalidServiceException(Exception): # noqa: N818 |
118 | 142 | """ |
119 | 143 | The service passed in config is not found |
@@ -1405,21 +1429,29 @@ def create_dbt_tests_definition(self, dbt_test: dict) -> Iterable[Either[CreateT |
1405 | 1429 | fqn=manifest_node.name, |
1406 | 1430 | entity=TestDefinition, |
1407 | 1431 | ) |
| 1432 | + description = _get_dbt_test_description(manifest_node) |
1408 | 1433 | if not check_test_definition_exists: |
1409 | 1434 | entity_type = EntityType.TABLE |
1410 | 1435 | if get_manifest_column_name(manifest_node): |
1411 | 1436 | entity_type = EntityType.COLUMN |
1412 | 1437 | yield Either( |
1413 | 1438 | right=CreateTestDefinitionRequest( |
1414 | 1439 | name=manifest_node.name, |
1415 | | - description=manifest_node.description, |
| 1440 | + description=description, |
1416 | 1441 | entityType=entity_type, |
1417 | 1442 | testPlatforms=[TestPlatform.dbt], |
1418 | 1443 | parameterDefinition=create_test_case_parameter_definitions(manifest_node), |
1419 | 1444 | displayName=None, |
1420 | 1445 | owners=None, |
1421 | 1446 | ) |
1422 | 1447 | ) |
| 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 | + ) |
1423 | 1455 | except Exception as err: # pylint: disable=broad-except |
1424 | 1456 | yield Either( |
1425 | 1457 | left=StackTraceError( |
@@ -1454,19 +1486,27 @@ def create_dbt_test_case(self, dbt_test: dict) -> Iterable[Either[CreateTestCase |
1454 | 1486 | ) |
1455 | 1487 |
|
1456 | 1488 | test_case = self.metadata.get_by_name(TestCase, test_case_fqn, fields=["testDefinition,testSuite"]) |
| 1489 | + description = _get_dbt_test_description(manifest_node) |
1457 | 1490 | if test_case is None: |
1458 | 1491 | # Create the test case only if it does not exist |
1459 | 1492 | yield Either( |
1460 | 1493 | right=CreateTestCaseRequest( |
1461 | 1494 | name=manifest_node.name, |
1462 | | - description=manifest_node.description, |
| 1495 | + description=description, |
1463 | 1496 | testDefinition=FullyQualifiedEntityName(manifest_node.name), |
1464 | 1497 | entityLink=entity_link_str, |
1465 | 1498 | parameterValues=create_test_case_parameter_values(dbt_test), |
1466 | 1499 | displayName=None, |
1467 | 1500 | owners=None, |
1468 | 1501 | ) |
1469 | 1502 | ) |
| 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 | + ) |
1470 | 1510 | logger.debug(f"Test case Already Exists: {test_case_fqn}") |
1471 | 1511 | except Exception as err: # pylint: disable=broad-except |
1472 | 1512 | yield Either( |
|
0 commit comments