From 103f980a9c8e09f53a5443d6ff659bb376481c78 Mon Sep 17 00:00:00 2001 From: Dylan Audius Date: Tue, 16 Jun 2026 12:02:32 -0700 Subject: [PATCH] fix(common): pass freeform genres through to SDK instead of reverting to Electronic toSdkGenre in the track adapter filtered out any value not in the canonical Genre enum and returned undefined, which then fell back to DEFAULT_GENRE (Electronic) before reaching the SDK. As a result, custom/freeform genres entered by artists were silently lost on save, even though the API, ETL indexer, and SDK upload schema all already accept any non-empty string up to 100 chars. Now any non-empty genre string is passed through unchanged; the empty case still falls back to Electronic (genre is required). Removes the now-unused VALID_GENRES set and adds regression tests. Re-applies the fix from #14465, which was closed inadvertently after the backend half (go-openaudio #351) merged. Co-Authored-By: Claude Opus 4.8 (1M context) --- .changeset/fix-freeform-genre-adapter.md | 5 +++++ packages/common/src/adapters/track.test.ts | 22 ++++++++++++++++++++++ packages/common/src/adapters/track.ts | 17 ++++++++++------- 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 .changeset/fix-freeform-genre-adapter.md diff --git a/.changeset/fix-freeform-genre-adapter.md b/.changeset/fix-freeform-genre-adapter.md new file mode 100644 index 00000000000..b07ac3a7518 --- /dev/null +++ b/.changeset/fix-freeform-genre-adapter.md @@ -0,0 +1,5 @@ +--- +'@audius/common': patch +--- + +Fix freeform/custom track genres silently reverting to Electronic on save. `toSdkGenre` in the track adapter filtered out any value not in the canonical `Genre` enum and returned `undefined`, which then fell back to `DEFAULT_GENRE` (Electronic) before reaching the SDK. Now any non-empty genre string is passed through unchanged (the SDK upload schema already caps it at 100 chars), so custom genres entered by artists are preserved end-to-end. diff --git a/packages/common/src/adapters/track.test.ts b/packages/common/src/adapters/track.test.ts index fbcd3446d6d..0acd748422d 100644 --- a/packages/common/src/adapters/track.test.ts +++ b/packages/common/src/adapters/track.test.ts @@ -30,4 +30,26 @@ describe('trackMetadataForUploadToSdk', () => { expect(result.allowedApiKeys).toBeNull() }) + + it('passes a freeform/custom genre through to the SDK unchanged', () => { + const result = trackMetadataForUploadToSdk( + makeMetadata({ genre: 'Ambient Drone' }) + ) + + expect(result.genre).toBe('Ambient Drone') + }) + + it('preserves a canonical genre', () => { + const result = trackMetadataForUploadToSdk( + makeMetadata({ genre: Genre.HipHopRap }) + ) + + expect(result.genre).toBe(Genre.HipHopRap) + }) + + it('falls back to Electronic only when genre is empty', () => { + const result = trackMetadataForUploadToSdk(makeMetadata({ genre: '' })) + + expect(result.genre).toBe(Genre.Electronic) + }) }) diff --git a/packages/common/src/adapters/track.ts b/packages/common/src/adapters/track.ts index 16ee8edb846..9f1a9535d46 100644 --- a/packages/common/src/adapters/track.ts +++ b/packages/common/src/adapters/track.ts @@ -38,16 +38,19 @@ import { repostFromSDK } from './repost' import { userMetadataFromSDK } from './user' import { transformAndCleanList } from './utils' -const VALID_GENRES = new Set(Object.values(Genre)) const VALID_MOODS = new Set(Object.values(Mood)) -function toSdkGenre( - value: string | undefined | '' -): (typeof Genre)[keyof typeof Genre] | undefined { +/** + * Pass through any non-empty genre string to the SDK. Canonical Genre enum + * values are returned as-is; freeform strings are also passed through + * unchanged so artists can enter custom genres (the SDK upload schema caps + * them at 100 chars). Previously this filtered out any value not in the + * canonical Genre enum, which caused custom genres to silently fall back to + * Electronic. + */ +function toSdkGenre(value: string | undefined | ''): string | undefined { if (value === undefined || value === '') return undefined - return VALID_GENRES.has(value) - ? (value as (typeof Genre)[keyof typeof Genre]) - : undefined + return value } function toSdkMood(