Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -- handle empty string dashboard run timestamps #2277

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading