From f88a7878154287a8fe2520c33936c1e0807c3aac Mon Sep 17 00:00:00 2001 From: Ben Dye Date: Fri, 1 Nov 2024 13:09:38 -0400 Subject: [PATCH 1/4] handle empty string dashboard run timestamps Signed-off-by: Ben Dye --- .../metadata_service/proxy/neo4j_proxy.py | 2 +- metadata/tests/unit/proxy/test_neo4j_proxy.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/metadata/metadata_service/proxy/neo4j_proxy.py b/metadata/metadata_service/proxy/neo4j_proxy.py index 7ae3e358da..e3f927bf77 100644 --- a/metadata/metadata_service/proxy/neo4j_proxy.py +++ b/metadata/metadata_service/proxy/neo4j_proxy.py @@ -1603,7 +1603,7 @@ def get_dashboard_by_user_relation(self, *, user_email: str, relation_type: User name=record['name'], url=record['url'], description=record['description'], - last_successful_run_timestamp=record['last_successful_run_timestamp'], + last_successful_run_timestamp=record['last_successful_run_timestamp'] if record['last_successful_run_timestamp'] != '' else None, )) return {ResourceType.Dashboard.name.lower(): results} diff --git a/metadata/tests/unit/proxy/test_neo4j_proxy.py b/metadata/tests/unit/proxy/test_neo4j_proxy.py index 94fbcd79e5..fee2b72958 100644 --- a/metadata/tests/unit/proxy/test_neo4j_proxy.py +++ b/metadata/tests/unit/proxy/test_neo4j_proxy.py @@ -1182,6 +1182,42 @@ def test_get_dashboard_by_user_relation(self) -> None: self.assertEqual(len(result['dashboard']), 1) self.assertEqual(expected, result['dashboard'][0]) + def test_get_dashboard_by_user_relation_empty_string_last_successful_run_timestamp(self) -> None: + """ + Expect last_successful_run_timestamp to be None if value in DB is empty string. + """ + with patch.object(GraphDatabase, 'driver'), patch.object(Neo4jProxy, '_execute_cypher_query') as mock_execute: + mock_execute.return_value = [ + { + 'uri': 'dashboard_uri', + 'cluster_name': 'cluster', + 'dg_name': 'dashboard_group', + 'dg_url': 'http://foo.bar/group', + 'product': 'foobar', + 'name': 'dashboard', + 'url': 'http://foo.bar/dashboard', + 'description': 'description', + 'last_successful_run_timestamp': '' + } + ] + + neo4j_proxy = Neo4jProxy(host='neo4j://example.com', port=0000) + result = neo4j_proxy.get_dashboard_by_user_relation(user_email='test_user', + relation_type=UserResourceRel.follow) + + expected = DashboardSummary(uri='dashboard_uri', + cluster='cluster', + group_name='dashboard_group', + group_url='http://foo.bar/group', + product='foobar', + name='dashboard', + url='http://foo.bar/dashboard', + description='description', + last_successful_run_timestamp=None) + + self.assertEqual(len(result['dashboard']), 1) + self.assertEqual(expected, result['dashboard'][0]) + def test_add_resource_relation_by_user(self) -> None: with patch.object(GraphDatabase, 'driver') as mock_driver: mock_session = MagicMock() From b2abc29f39c513920ee57dfee3247c6ee7672018 Mon Sep 17 00:00:00 2001 From: Ben Dye Date: Fri, 1 Nov 2024 13:19:29 -0400 Subject: [PATCH 2/4] linter Signed-off-by: Ben Dye --- metadata/metadata_service/proxy/neo4j_proxy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/metadata/metadata_service/proxy/neo4j_proxy.py b/metadata/metadata_service/proxy/neo4j_proxy.py index e3f927bf77..f132b5d842 100644 --- a/metadata/metadata_service/proxy/neo4j_proxy.py +++ b/metadata/metadata_service/proxy/neo4j_proxy.py @@ -1594,6 +1594,10 @@ def get_dashboard_by_user_relation(self, *, user_email: str, relation_type: User results = [] for record in records: + last_successful_run_timestamp = record['last_successful_run_timestamp'] + if record['last_successful_run_timestamp'] == '': + last_successful_run_timestamp = None + results.append(DashboardSummary( uri=record['uri'], cluster=record['cluster_name'], @@ -1603,7 +1607,7 @@ def get_dashboard_by_user_relation(self, *, user_email: str, relation_type: User name=record['name'], url=record['url'], description=record['description'], - last_successful_run_timestamp=record['last_successful_run_timestamp'] if record['last_successful_run_timestamp'] != '' else None, + last_successful_run_timestamp=last_successful_run_timestamp, )) return {ResourceType.Dashboard.name.lower(): results} From 781123e30c1079ef23d54b8e386ce0fd77d66307 Mon Sep 17 00:00:00 2001 From: Ben Dye Date: Fri, 1 Nov 2024 13:54:14 -0400 Subject: [PATCH 3/4] mypy ignore for unrelated line Signed-off-by: Ben Dye --- metadata/metadata_service/proxy/neo4j_proxy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metadata/metadata_service/proxy/neo4j_proxy.py b/metadata/metadata_service/proxy/neo4j_proxy.py index f132b5d842..8af39e69a9 100644 --- a/metadata/metadata_service/proxy/neo4j_proxy.py +++ b/metadata/metadata_service/proxy/neo4j_proxy.py @@ -624,7 +624,8 @@ def get_resource_description(self, *, param_dict={'key': uri}) result = get_single_record(result) - return Description(description=result['description'] if result else None) + + return Description(description=result['description'] if result else None) # type: ignore @timer_with_counter def get_table_description(self, *, From 0ceb7cdbed3c2ecebcefc5aac3d5f3a7033b521e Mon Sep 17 00:00:00 2001 From: Ben Dye Date: Fri, 1 Nov 2024 14:02:13 -0400 Subject: [PATCH 4/4] cleanup Signed-off-by: Ben Dye --- metadata/metadata_service/proxy/neo4j_proxy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/metadata/metadata_service/proxy/neo4j_proxy.py b/metadata/metadata_service/proxy/neo4j_proxy.py index 8af39e69a9..2966d76a14 100644 --- a/metadata/metadata_service/proxy/neo4j_proxy.py +++ b/metadata/metadata_service/proxy/neo4j_proxy.py @@ -624,7 +624,6 @@ def get_resource_description(self, *, param_dict={'key': uri}) result = get_single_record(result) - return Description(description=result['description'] if result else None) # type: ignore @timer_with_counter