Skip to content

Commit

Permalink
fix(python-sdk): DataHubGraph get_aspect should accept empty responses (
Browse files Browse the repository at this point in the history
  • Loading branch information
shirshanka authored and szalai1 committed Dec 22, 2022
1 parent dd7d732 commit 9c76204
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metadata-ingestion/src/datahub/ingestion/graph/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_aspect(

# Deserialize the aspect json into the aspect type.
aspect_json = response_json.get("aspect", {}).get(aspect_type_name)
if aspect_json:
if aspect_json is not None:
# need to apply a transform to the response to match rest.li and avro serialization
post_json_obj = post_json_transform(aspect_json)
return aspect_type.from_obj(post_json_obj)
Expand Down
23 changes: 23 additions & 0 deletions metadata-ingestion/tests/unit/graph/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from unittest.mock import Mock, patch

from datahub.ingestion.graph.client import DataHubGraph, DataHubGraphConfig
from datahub.metadata.schema_classes import CorpUserEditableInfoClass


@patch("datahub.ingestion.graph.client.telemetry_enabled", False)
@patch("datahub.emitter.rest_emitter.DataHubRestEmitter.test_connection")
def test_get_aspect(mock_test_connection):
mock_test_connection.return_value = {}
graph = DataHubGraph(DataHubGraphConfig())
user_urn = "urn:li:corpuser:foo"
with patch("requests.Session.get") as mock_get:
mock_response = Mock()
mock_response.json = Mock(
return_value={
"version": 0,
"aspect": {"com.linkedin.identity.CorpUserEditableInfo": {}},
}
)
mock_get.return_value = mock_response
editable = graph.get_aspect(user_urn, CorpUserEditableInfoClass)
assert editable is not None

0 comments on commit 9c76204

Please sign in to comment.