Fix cross-team asset 401 and stale label associations in QC script#38
Open
salmanfarisvp wants to merge 1 commit into
Open
Fix cross-team asset 401 and stale label associations in QC script#38salmanfarisvp wants to merge 1 commit into
salmanfarisvp wants to merge 1 commit into
Conversation
The QC script was failing with 401 when adding assets to playlists because GET /v4/assets returns cross-team assets that the token's RLS policy blocks on insert (42501 insufficient_privilege). Fixed by fetching the current team_id and filtering assets by team_id in the query. Also fixed delete_playlist() to explicitly remove labels/playlists associations before deleting a playlist, preventing stale rows that caused POST /v4/labels/playlists to fail on subsequent runs. Additional improvements: - Add resolution=ignore-duplicates to POST /v4/labels/playlists as a safety net against any remaining stale associations - Add progress logging in create_qc_playlist() to make it clear which step fails when errors occur - Rename error message from "Unable to create playlist" to "QC playlist setup failed" to better reflect that the failure may occur in asset-adding or label-linking steps, not just creation
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.
Summary
GET /v4/assetsreturns cross-team shared assets that the token's RLS policy blocks on insert (42501 insufficient_privilege→ HTTP 401). The script was randomly picking these assets, causing consistent failures atPOST /v4/playlist-items.delete_playlist()was not removinglabels/playlistsassociations before deleting a playlist, leaving stale rows that causedPOST /v4/labels/playliststo fail on subsequent runs.Changes
Fix cross-team asset 401
get_team_id()helper that fetches the current account's team ID viaGET /v4/labels?type=eq.all-screensget_ten_random_assets()to acceptteam_idand filter the assets query withteam_id=eq.{team_id}, ensuring only same-team assets (which the token can insert) are selectedFix stale label associations
delete_playlist()to explicitly callDELETE /v4/labels/playlists?playlist_id=eq.{id}before deleting playlist items and the playlist itselfresolution=ignore-duplicatesto thePreferheader inPOST /v4/labels/playlistsas a safety netBetter observability
Playlist created,Adding assets to playlist...,Assigning playlist to all screens...) so future failures are immediately pinpointed to the exact step"Unable to create playlist"to"QC playlist setup failed"since it covers asset-adding and label-linking failures tooAPI Issues Raised
These are workarounds for underlying API inconsistencies that have been raised as an engineering ticket:
GET /v4/assetsshould not return assets the token cannot write — or should clearly mark them as read-only/cross-team403 Forbidden, not401 UnauthorizedDELETE /v4/playlistsshould cascade-deletelabels/playlistsrowsTest plan
delete_playlist()cleans up label associations on each runget_ten_random_assets()only returns same-team assets