From db182e4639490cb9e07ad6864ef9c52b5c2e4bb9 Mon Sep 17 00:00:00 2001 From: Shirshanka Das Date: Wed, 14 Dec 2022 10:40:16 -0800 Subject: [PATCH] fix(python-sdk): DataHubGraph get_aspect should accept empty responses (#6760) --- .../src/datahub/ingestion/graph/client.py | 2 +- .../tests/unit/graph/test_client.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 metadata-ingestion/tests/unit/graph/test_client.py diff --git a/metadata-ingestion/src/datahub/ingestion/graph/client.py b/metadata-ingestion/src/datahub/ingestion/graph/client.py index 5004240bd7c94..e8ba2007661ec 100644 --- a/metadata-ingestion/src/datahub/ingestion/graph/client.py +++ b/metadata-ingestion/src/datahub/ingestion/graph/client.py @@ -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) diff --git a/metadata-ingestion/tests/unit/graph/test_client.py b/metadata-ingestion/tests/unit/graph/test_client.py new file mode 100644 index 0000000000000..5f98aa46636e3 --- /dev/null +++ b/metadata-ingestion/tests/unit/graph/test_client.py @@ -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