Skip to content

Commit 8f185fd

Browse files
authored
fix(compare-dashboards): Remove no project error return (#93063)
Noticed from [this sentry issue](https://sentry.sentry.io/issues/6662011508/) that the comparison script is returning because there are no projects but this should be fine to run the rest of the script so I'm taking it out and making sure its formatted properly instead.
1 parent f86c8e4 commit 8f185fd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/sentry/discover/compare_tables.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import sentry_sdk
66

7+
from sentry.constants import ObjectStatus
78
from sentry.discover.arithmetic import is_equation
89
from sentry.discover.dataset_split import _get_equation_list, _get_field_list
910
from sentry.discover.translation.mep_to_eap import (
@@ -97,7 +98,11 @@ def compare_tables_for_dashboard_widget_queries(
9798
widget: DashboardWidget = widget_query.widget
9899
dashboard: Dashboard = widget.dashboard
99100
organization: Organization = dashboard.organization
100-
projects: list[Project] = list(dashboard.projects.all())
101+
# if the dashboard has no projects, we will use all projects in the organization
102+
projects = dashboard.projects.all() or Project.objects.filter(
103+
organization_id=dashboard.organization.id, status=ObjectStatus.ACTIVE
104+
)
105+
101106
if len(list(projects)) == 0:
102107
return {
103108
"passed": False,

tests/sentry/discover/test_compare_tables.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,29 @@ def setUp(self):
3232
self.dashboard = self.create_dashboard(
3333
organization=self.organization, filters={"environment": []}
3434
)
35+
self.dashboard_2 = self.create_dashboard(
36+
organization=self.organization, filters={"environment": []}
37+
)
3538
self.dashboard.projects.set([self.project])
39+
self.dashboard_2.projects.set([])
40+
41+
self.successful_widget_2 = DashboardWidget.objects.create(
42+
dashboard=self.dashboard_2,
43+
title="Test Successful Widget 2",
44+
order=0,
45+
display_type=DashboardWidgetDisplayTypes.TABLE,
46+
widget_type=DashboardWidgetTypes.TRANSACTION_LIKE,
47+
)
48+
49+
self.successful_widget_query_2 = DashboardWidgetQuery.objects.create(
50+
widget=self.successful_widget_2,
51+
name="Test Successful Widget Query 2",
52+
order=0,
53+
conditions="",
54+
aggregates=["count()"],
55+
columns=["count()", "transaction"],
56+
fields=["count()", "transaction"],
57+
)
3658

3759
self.successful_widget = DashboardWidget.objects.create(
3860
dashboard=self.dashboard,
@@ -299,3 +321,10 @@ def test_compare_non_existent_eap_widget_query(self):
299321
assert comparison_result["passed"] is False
300322
assert comparison_result["reason"] == CompareTableResult.QUERY_FAILED
301323
assert comparison_result["mismatches"] is not None and [] == comparison_result["mismatches"]
324+
325+
def test_compare_widget_query_with_no_project(self):
326+
comparison_result = compare_tables_for_dashboard_widget_queries(
327+
self.successful_widget_query_2
328+
)
329+
assert comparison_result["passed"] is True
330+
assert comparison_result["mismatches"] == []

0 commit comments

Comments
 (0)