Skip to content

Commit 58b604b

Browse files
committed
update description generation logic
1 parent 2117ed3 commit 58b604b

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

metadata-ingestion/src/datahub/ingestion/source/salesforce.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class SalesforceSourceReport(StaleEntityRemovalSourceReport):
178178
default_factory=LossyList
179179
)
180180

181+
num_objects_missing_formula: int = 0
182+
181183
def report_dropped(self, ent_name: str) -> None:
182184
self.filtered.append(ent_name)
183185

@@ -636,8 +638,14 @@ def get_salesforce_object_workunits(
636638
# Although formula is present in Metadata column of CustomField entity,
637639
# we can not use it as it allows querying only for one field at a time
638640
# and that would not be performant
639-
self.report.objects_with_calculated_field.append(sObjectName)
640641
calculated_field_formulae = self.get_calculated_field_formulae(sObjectName)
642+
if calculated_field_formulae:
643+
self.report.objects_with_calculated_field.append(sObjectName)
644+
else:
645+
# For some objects, although some fields are calculated, formula is absent
646+
# These are typically salesforce system calculated fields whose formula
647+
# is not exposed
648+
self.report.num_objects_missing_formula += 1
641649
else:
642650
calculated_field_formulae = {}
643651

@@ -851,26 +859,27 @@ def _get_field_description(
851859
customField: Optional[CustomField],
852860
formula: Optional[str],
853861
) -> str:
854-
if "Label" not in field or field["Label"] is None:
855-
desc = ""
856-
elif field["Label"].startswith("#"):
857-
desc = "\\" + field["Label"]
858-
else:
859-
desc = field["Label"]
862+
description_parts: List[str] = []
863+
864+
if field.get("Label") and field["Label"].startswith("#"):
865+
description_parts.append("\\" + field["Label"])
866+
elif field.get("Label"):
867+
description_parts.append(field["Label"])
860868

861869
text = field.get("FieldDefinition", {}).get("Description", None)
862870
if text:
863871
prefix = "\\" if text.startswith("#") else ""
864-
desc += f"\n\n{prefix}{text}"
872+
description_parts.append(f"{prefix}{text}")
865873

866874
text = field.get("InlineHelpText")
867875
if text:
868876
prefix = "\\" if text.startswith("#") else ""
869-
desc += f"\n\n{prefix}{text}"
877+
description_parts.append(f"{prefix}{text}")
870878

871879
if formula:
872-
desc += f"\n\nFormula: {formula}"
873-
return desc
880+
description_parts.append(f"Formula: {formula}")
881+
882+
return "\n\n".join(description_parts)
874883

875884
# Here jsonProps is used to add additional salesforce field level properties.
876885
def _get_field_json_props(
@@ -881,6 +890,9 @@ def _get_field_json_props(
881890
if field.get("IsUnique"):
882891
jsonProps["IsUnique"] = True
883892

893+
if field.get("IsCalculated"):
894+
jsonProps["IsCalculated"] = True
895+
884896
return json.dumps(jsonProps)
885897

886898
def _get_schema_field(

metadata-ingestion/tests/integration/salesforce/salesforce_mces_golden.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@
12051205
]
12061206
},
12071207
"isPartOfKey": false,
1208-
"jsonProps": "{}"
1208+
"jsonProps": "{\"IsCalculated\": true}"
12091209
},
12101210
{
12111211
"fieldPath": "Active__c",
@@ -1372,7 +1372,7 @@
13721372
{
13731373
"fieldPath": "Blank_Label",
13741374
"nullable": true,
1375-
"description": "\n\nThis is the # description\n\n\\# Help Text",
1375+
"description": "This is the # description\n\n\\# Help Text",
13761376
"type": {
13771377
"type": {
13781378
"com.linkedin.schema.StringType": {}

metadata-ingestion/tests/integration/salesforce/salesforce_mces_with_lineage_golden.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@
12051205
]
12061206
},
12071207
"isPartOfKey": false,
1208-
"jsonProps": "{}"
1208+
"jsonProps": "{\"IsCalculated\": true}"
12091209
},
12101210
{
12111211
"fieldPath": "Active__c",
@@ -1372,7 +1372,7 @@
13721372
{
13731373
"fieldPath": "Blank_Label",
13741374
"nullable": true,
1375-
"description": "\n\nThis is the # description\n\n\\# Help Text",
1375+
"description": "This is the # description\n\n\\# Help Text",
13761376
"type": {
13771377
"type": {
13781378
"com.linkedin.schema.StringType": {}

0 commit comments

Comments
 (0)