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

feat(issue-views): Update GET endpoint to validate view's projects #84338

Merged
merged 7 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/sentry/issues/endpoints/organization_group_search_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ def get(self, request: Request, organization: Organization) -> Response:
)

if not has_global_views:
for view in query:
if view.is_all_projects or view.projects.count() > 1 or view.projects.count() == 0:
views_to_updates = []
default_project = pick_default_project(organization, request.user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this query might not be necessary if all the views have a single project, so we can make this even better if we avoid it in that case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is handled by Django's lazy loading of query sets - so if default project is never accessed in the for loop after this, the DB query isn't actually made.


for view in query.prefetch_related("projects"):
if view.is_all_projects or view.projects.count() != 1:
view.is_all_projects = False
view.projects.set([pick_default_project(organization, request.user)])
view.save()
view.projects.set([default_project])
MichaelSun48 marked this conversation as resolved.
Show resolved Hide resolved
views_to_updates.append(view)

GroupSearchView.objects.bulk_update(views_to_updates, ["is_all_projects"])
MichaelSun48 marked this conversation as resolved.
Show resolved Hide resolved

return self.paginate(
request=request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_not_including_page_filters_does_not_reset_them_for_existing_views(self)
# Original Page filters
assert views[0]["timeFilters"] == {"period": "14d"}
assert views[0]["projects"] == [self.project1.id]
assert views[0]["environments"] == ["production"]
assert views[0]["environments"] == []

view = views[0]
# Change nothing but the name
Expand Down
Loading