Skip to content

Commit

Permalink
Fix -- handle empty string dashboard run timestamps (#2277)
Browse files Browse the repository at this point in the history
* handle empty string dashboard run timestamps

Signed-off-by: Ben Dye <bdye@lyft.com>

* linter

Signed-off-by: Ben Dye <bdye@lyft.com>

* mypy ignore for unrelated line

Signed-off-by: Ben Dye <bdye@lyft.com>

* cleanup

Signed-off-by: Ben Dye <bdye@lyft.com>

---------

Signed-off-by: Ben Dye <bdye@lyft.com>
  • Loading branch information
B-T-D authored Nov 1, 2024
1 parent ade1bdf commit 1586fcb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions metadata/metadata_service/proxy/neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ 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, *,
Expand Down Expand Up @@ -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'],
Expand All @@ -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'],
last_successful_run_timestamp=last_successful_run_timestamp,
))

return {ResourceType.Dashboard.name.lower(): results}
Expand Down
36 changes: 36 additions & 0 deletions metadata/tests/unit/proxy/test_neo4j_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1586fcb

Please sign in to comment.