Description
The M3U import process fails with a "Something went wrong" error when the playlist file contains duplicate tracks. While
the preview works correctly, the database transaction fails during the save operation.
Root Cause Analysis
The issue lies in mobile/src/data/playlist/api.ts. When createPlaylist or updatePlaylist is called, it attempts to insert
rows into the tracks_to_playlists table. If the M3U contains the same track multiple times, the Drizzle ORM transaction
hits a SQLite constraint violation because the table expects a unique combination of playlistName and trackId (or similar
primary key constraints defined in the schema).
Suggested Fix
Adding .onConflictDoNothing() to the insert operations in the playlist API prevents the transaction from failing when
duplicate tracks are encountered.
In mobile/src/data/playlist/api.ts:
1 // For createPlaylist
2 await tx.insert(tracksToPlaylists).values(
3 entry.tracks.map((t, position) => {
4 return { playlistName: name, trackId: t.id, position };
5 }),
6 ).onConflictDoNothing(); // <--- Add this
7
8 // And similarly for updatePlaylist
9 await tx.insert(tracksToPlaylists).values(
10 tracks.map((t, position) => {
11 const latestName = sanitizedName ?? id;
12 return { playlistName: latestName, trackId: t.id, position };
13 }),
14 ).onConflictDoNothing(); // <--- Add this
Steps to Reproduce
- Create an M3U file where the same file path is listed twice.
- Import the M3U in the app.
- Observe the success in preview but failure upon clicking "Save".
Description
The M3U import process fails with a "Something went wrong" error when the playlist file contains duplicate tracks. While
the preview works correctly, the database transaction fails during the save operation.
Root Cause Analysis
The issue lies in mobile/src/data/playlist/api.ts. When createPlaylist or updatePlaylist is called, it attempts to insert
rows into the tracks_to_playlists table. If the M3U contains the same track multiple times, the Drizzle ORM transaction
hits a SQLite constraint violation because the table expects a unique combination of playlistName and trackId (or similar
primary key constraints defined in the schema).
Suggested Fix
Adding .onConflictDoNothing() to the insert operations in the playlist API prevents the transaction from failing when
duplicate tracks are encountered.
In mobile/src/data/playlist/api.ts:
10 tracks.map((t, position) => {
11 const latestName = sanitizedName ?? id;
12 return { playlistName: latestName, trackId: t.id, position };
13 }),
14 ).onConflictDoNothing(); // <--- Add this
Steps to Reproduce