Skip to content

Commit

Permalink
fix(sdk): platform resource api for non existent resources (datahub-p…
Browse files Browse the repository at this point in the history
  • Loading branch information
shirshanka authored Oct 14, 2024
1 parent 4133319 commit 38ac100
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,17 @@ def to_datahub(self, graph_client: DataHubGraph) -> None:
def from_datahub(
cls, graph_client: DataHubGraph, key: Union[PlatformResourceKey, str]
) -> Optional["PlatformResource"]:
"""
Fetches a PlatformResource from the graph given a key.
Key can be either a PlatformResourceKey object or an urn string.
Returns None if the resource is not found.
"""
if isinstance(key, PlatformResourceKey):
urn = PlatformResourceUrn(id=key.id)
else:
urn = PlatformResourceUrn.from_string(key)
if not graph_client.exists(str(urn)):
return None
platform_resource = graph_client.get_entity_semityped(str(urn))
return cls(
id=urn.id,
Expand Down
13 changes: 13 additions & 0 deletions smoke-test/tests/platform_resources/test_platform_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,16 @@ def test_platform_resource_search(graph_client, test_id, cleanup_resources):
]
assert len(search_results) == 1
assert search_results[0] == platform_resource


def test_platform_resource_non_existent(graph_client, test_id):
key = PlatformResourceKey(
platform=f"test_platform_{test_id}",
resource_type=f"test_resource_type_{test_id}",
primary_key=f"test_primary_key_{test_id}",
)
platform_resource = PlatformResource.from_datahub(
key=key,
graph_client=graph_client,
)
assert platform_resource is None

0 comments on commit 38ac100

Please sign in to comment.