Skip to content

fix(compare-dashboards): Remove no project error return #93063

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

Merged
merged 3 commits into from
Jun 9, 2025
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
7 changes: 6 additions & 1 deletion src/sentry/discover/compare_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sentry_sdk

from sentry.constants import ObjectStatus
from sentry.discover.arithmetic import is_equation
from sentry.discover.dataset_split import _get_equation_list, _get_field_list
from sentry.discover.translation.mep_to_eap import (
Expand Down Expand Up @@ -97,7 +98,11 @@ def compare_tables_for_dashboard_widget_queries(
widget: DashboardWidget = widget_query.widget
dashboard: Dashboard = widget.dashboard
organization: Organization = dashboard.organization
projects: list[Project] = list(dashboard.projects.all())
# if the dashboard has no projects, we will use all projects in the organization
projects = dashboard.projects.all() or Project.objects.filter(
organization_id=dashboard.organization.id, status=ObjectStatus.ACTIVE
)

if len(list(projects)) == 0:
return {
"passed": False,
Expand Down
29 changes: 29 additions & 0 deletions tests/sentry/discover/test_compare_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ def setUp(self):
self.dashboard = self.create_dashboard(
organization=self.organization, filters={"environment": []}
)
self.dashboard_2 = self.create_dashboard(
organization=self.organization, filters={"environment": []}
)
self.dashboard.projects.set([self.project])
self.dashboard_2.projects.set([])

self.successful_widget_2 = DashboardWidget.objects.create(
dashboard=self.dashboard_2,
title="Test Successful Widget 2",
order=0,
display_type=DashboardWidgetDisplayTypes.TABLE,
widget_type=DashboardWidgetTypes.TRANSACTION_LIKE,
)

self.successful_widget_query_2 = DashboardWidgetQuery.objects.create(
widget=self.successful_widget_2,
name="Test Successful Widget Query 2",
order=0,
conditions="",
aggregates=["count()"],
columns=["count()", "transaction"],
fields=["count()", "transaction"],
)

self.successful_widget = DashboardWidget.objects.create(
dashboard=self.dashboard,
Expand Down Expand Up @@ -299,3 +321,10 @@ def test_compare_non_existent_eap_widget_query(self):
assert comparison_result["passed"] is False
assert comparison_result["reason"] == CompareTableResult.QUERY_FAILED
assert comparison_result["mismatches"] is not None and [] == comparison_result["mismatches"]

def test_compare_widget_query_with_no_project(self):
comparison_result = compare_tables_for_dashboard_widget_queries(
self.successful_widget_query_2
)
assert comparison_result["passed"] is True
assert comparison_result["mismatches"] == []
Loading