ref(dashboards): Use favorited column for favorite status instead of row existence#110204
Merged
DominikB2014 merged 5 commits intomasterfrom Mar 9, 2026
Conversation
…row existence Check favorited=True instead of row existence to determine favorite status. Unfavoriting now sets favorited=False and clears position instead of deleting the row. Re-favoriting reactivates existing unfavorited entries. Rename delete_favorite_dashboard to unfavorite_dashboard to reflect the new behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use select_for_update() to lock existing rows when favoriting a dashboard, preventing concurrent calls from racing between the check and insert and causing IntegrityError on the unique constraint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…hboard The global self.count() check included unfavorited rows and other users' rows, causing position to be 1 instead of 0 when a user favorites their first dashboard after having previously unfavorited all others. Check for existing favorited rows scoped to the user and organization instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…olumn Update the deprecated favorited_by setter to set favorited=False instead of deleting rows, consistent with the new unfavorite behavior. Also handles re-favoriting existing unfavorited entries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
edwardgou-sentry
approved these changes
Mar 9, 2026
Contributor
edwardgou-sentry
left a comment
There was a problem hiding this comment.
Makes sense to me. I'm assuming the update to prebuilt dashboard sync will be in another pr? There's also one cursor comment, but looks like an easy fix
Contributor
Author
@edwardgou-sentry yup! Gonna follow up with a sync, will fix the cursor comment too |
…vorite The deprecated favorited_by setter was not clearing position when unfavoriting, unlike unfavorite_dashboard which sets position=None. The UniqueConstraint on (user_id, organization_id, position) applies regardless of favorited status, so a stale non-null position on a favorited=False row could cause IntegrityError when insert_favorite_dashboard assigns the same position. Also fix re-favoriting to assign a correct position instead of leaving it null. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DominikB2014
added a commit
that referenced
this pull request
Mar 9, 2026
…0209) Adds a sync mechanism that automatically favorites certain prebuilt dashboards for users on first load, mirroring the pattern used in explore saved queries (`sync_prebuilt_queries_starred`). An optional `pre_favorited` field is added to the `PrebuiltDashboard` TypedDict. When set to `True`, `sync_prebuilt_dashboards_favorited()` creates `DashboardFavoriteUser` records for users who haven't interacted with those dashboards yet. This runs on the dashboards list GET endpoint with a user-scoped lock (separate from the org-scoped lock used for dashboard sync). The enabled prebuilt dashboard logic (option + feature flag check) is extracted into a shared `get_enabled_prebuilt_dashboards()` helper used by both sync functions. Pre-favorited dashboards: Backend Overview, Web Vitals, Mobile Vitals, AI Agents Overview, MCP Overview. Do not merge until #110204 merges --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use the
favoritedboolean column onDashboardFavoriteUserto determinefavorite status, rather than checking for existence of a row in the table.
Previously, unfavoriting a dashboard deleted the
DashboardFavoriteUserrow entirely. Now it sets
favorited=Falseand clears the position, preservingthe row for potential re-favoriting. This avoids row churn and makes the
favorite state explicit.
Changes:
get_favorite_dashboards,get_favorite_dashboard,get_last_position,reorder_favorite_dashboards) now filter byfavorited=Trueinsert_favorite_dashboardreactivates existing unfavorited entries insteadof always creating new rows
delete_favorite_dashboard→unfavorite_dashboardto reflectthat the row is no longer deleted
queries to scope by
favorited=Trueinsert_favorite_dashboardusingselect_for_update()to prevent concurrent calls from causing
IntegrityErrorunfavoriting all others assigned position 1 instead of 0 due to a global
unscoped count check
Refs DAIN-1287