Skip to content

Fix playlist writes in client#13811

Merged
rickyrombo merged 3 commits intomainfrom
mjp-sdk-playlist-fixes
Mar 5, 2026
Merged

Fix playlist writes in client#13811
rickyrombo merged 3 commits intomainfrom
mjp-sdk-playlist-fixes

Conversation

@rickyrombo
Copy link
Contributor

  • publishTracks returns string track IDs, which were being incorrectly parsed as though they were numbers that needed converting. This was changed behavior from recent SDK changes made to match the POST endpoints as this was working previously
  • createPlaylist wasn't equipped to handle using a preset playlistId like our client expects, rejecting calls that had playlistId already set in the metadata (which would happen on our creation of playlists from scratch).
  • createPlaylistInternal was being passed parsed parameters in the createPlaylist case, and unparsed in the uploadPlaylist case, and used types that made it hard to squeeze both callsites in. This was resulting in incorrectly setting some IDs to hash IDs (eg in playlistContents) and was uncovered when fixing the playlistId bug above
  • updatePlaylist had incorrect schema still referencing coverArtCid instead of playlistImageSizesMultihash, blocking any playlist updates that included an image update

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 3700822

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@audius/sdk Patch
@audius/sdk-legacy Patch
@audius/sp-actions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes playlist/album publishing and updating flows to align with recent SDK ID and metadata schema changes, ensuring playlist creation/update works with client expectations and correct image fields.

Changes:

  • Allow preset playlistId in create-playlist metadata and tighten onProgress typing for playlist uploads.
  • Refactor createPlaylistInternal to parse inputs internally and normalize progress events for image uploads.
  • Fix playlist/album publish flow to stop incorrectly converting returned track IDs; update playlist update schema to use playlistImageSizesMultihash.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/sdk/src/sdk/api/playlists/types.ts Updates playlist create/update zod schemas (preset playlistId, progress handler typing, playlistImageSizesMultihash).
packages/sdk/src/sdk/api/playlists/PlaylistsApi.ts Refactors create-playlist entity-manager path and normalizes onProgress callbacks for cover art uploads.
packages/common/src/api/tan-query/upload/usePublishCollection.ts Stops mis-parsing published track IDs when building playlistContents for album/playlist creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +728 to +731
const { userId, imageFile, metadata, onProgress } = await parseParams(
'createPlaylistInternal',
CreatePlaylistSchema
)(params)
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

createPlaylistInternal parses CreatePlaylistSchema but then ignores playlistId and trackIds from the parsed result (it only reads metadata.playlistId). This is a functional regression for callsites that rely on trackIds to populate playlistContents, and for callers that pass playlistId at the top level. Consider: (1) destructuring playlistId and trackIds from the parsed params, (2) choosing the entity id from params.playlistId ?? metadata.playlistId ?? generatePlaylistId(), and (3) populating metadata.playlistContents from trackIds when provided (as uploadPlaylist does) to preserve existing behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +110
metadata.playlistContents = publishedTracks
.filter((t) => !!t.trackId)
.map((t) => ({
timestamp: Math.round(Date.now() / 1000),
trackId: t.trackId!,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Filtering out items where trackId is falsy will silently create an album with missing tracks if any track publish failed (previously this would error when trying to parse/convert the missing id). It’s safer to fail the mutation when any published track is missing trackId (or has an error) so the user doesn’t end up with a partially-created collection.

Copilot uses AI. Check for mistakes.
Comment on lines +122 to +126
metadata.playlistContents = publishedTracks
.filter((t) => !!t.trackId)
.map((t) => ({
timestamp: Math.round(Date.now() / 1000),
trackId: t.trackId!,
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Filtering out items where trackId is falsy will silently create a playlist with missing tracks if any track publish failed (previously this would error when trying to parse/convert the missing id). It’s safer to fail the mutation when any published track is missing trackId (or has an error) so the user doesn’t end up with a partially-created collection.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rickyrombo rickyrombo merged commit a7a9e17 into main Mar 5, 2026
3 checks passed
@rickyrombo rickyrombo deleted the mjp-sdk-playlist-fixes branch March 5, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants