Skip to content

Commit 309abf0

Browse files
committed
update mcp.py
1 parent 7c2ea0c commit 309abf0

File tree

1 file changed

+9
-4
lines changed
  • metadata-ingestion/src/datahub/emitter

1 file changed

+9
-4
lines changed

metadata-ingestion/src/datahub/emitter/mcp.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SystemMetadataClass,
1515
_Aspect,
1616
)
17-
from datahub.utilities.urns.urn import guess_entity_type
17+
from datahub.utilities.urns.urn import Urn, guess_entity_type
1818

1919
if TYPE_CHECKING:
2020
from datahub.ingestion.api.workunit import MetadataWorkUnit
@@ -63,15 +63,19 @@ class MetadataChangeProposalWrapper:
6363

6464
entityType: str = _ENTITY_TYPE_UNSET
6565
changeType: Union[str, ChangeTypeClass] = ChangeTypeClass.UPSERT
66-
entityUrn: Union[None, str] = None
66+
entityUrn: Union[None, str,] = None
6767
entityKeyAspect: Union[None, _Aspect] = None
6868
auditHeader: Union[None, KafkaAuditHeaderClass] = None
6969
aspectName: Union[None, str] = None
7070
aspect: Union[None, _Aspect] = None
7171
systemMetadata: Union[None, SystemMetadataClass] = None
7272

7373
def __post_init__(self) -> None:
74-
if self.entityUrn and self.entityType == _ENTITY_TYPE_UNSET:
74+
if isinstance(self.entityUrn, Urn):
75+
if self.entityType == _ENTITY_TYPE_UNSET:
76+
self.entityType = self.entityUrn.entity_type
77+
self.entityUrn = str(self.entityUrn)
78+
elif self.entityUrn and self.entityType == _ENTITY_TYPE_UNSET:
7579
self.entityType = guess_entity_type(self.entityUrn)
7680
elif self.entityUrn and self.entityType:
7781
guessed_entity_type = guess_entity_type(self.entityUrn).lower()
@@ -104,7 +108,8 @@ def construct_many(
104108
) -> List["MetadataChangeProposalWrapper"]:
105109
return [cls(entityUrn=entityUrn, aspect=aspect) for aspect in aspects if aspect]
106110

107-
def _make_mcp_without_aspects(self) -> MetadataChangeProposalClass:
111+
def _make_mcp_without_aspects(self) -> MetadataChangeProposalClass:
112+
assert self.entityUrn is None or isinstance(self.entityUrn, str)
108113
return MetadataChangeProposalClass(
109114
entityType=self.entityType,
110115
entityUrn=self.entityUrn,

0 commit comments

Comments
 (0)