Repository navigation
fix(catalog): match TMDB ids stored in TMDB's own id-slug form - #484
Conversation
Attaching a TMDB id compared the stored value byte-for-byte, so a
media_items row holding "1931-disney-s-adventures-of-the-gummi-bears"
conflicted with the bare "1931" being attached and the presence-lookup
backfill failed:
WARN requests: failed to backfill tmdb id from presence lookup
error="media item tmdb id conflict:
got \"1931-disney-s-adventures-of-the-gummi-bears\", want \"1931\""
That form is not corrupt data — it is how TMDB writes its own URLs
(/tv/1931-disney-s-adventures-of-the-gummi-bears) — and enough of it has
reached the catalog to matter. The visible cost is that a title already
in the library never gets linked, so clients keep offering to request
something you own.
The numeric prefix is the identity, so compare on that. Values with no
leading digits, or digits not followed by a separator, are not TMDB ids
and still conflict as before.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
📝 WalkthroughWalkthroughTMDB identifier handling now treats numeric slug forms and bare numeric IDs as equivalent during attachment conflict checks and ownership lookups. Tests cover normalization, invalid values, slug-form conflicts, and preservation of the target row after rejection. ChangesTMDB identifier normalization
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/catalog/provider_id_repo.go`:
- Line 102: Update AttachTMDBID’s cross-record ownership query to use the same
trimmed digits-then-suffix TMDB matching as sameTMDBID, rather than exact SQL
equality, so numeric and slug forms identify the existing owner. Preserve
current-row validation and add an AttachTMDBID regression test proving a numeric
ID cannot be attached when another content record owns the equivalent slug.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1a2c3d95-0b5e-4acb-b20e-7057808a4d76
📒 Files selected for processing (2)
internal/catalog/provider_id_repo.gointernal/catalog/provider_id_tmdb_match_test.go
Problem
Attaching a TMDB id compared the stored value byte-for-byte, so a
media_itemsrow holding TMDB's id-slug form conflicted with the bare numeric id being attached, and the presence-lookup backfill failed:That form is not corrupt data — it is how TMDB writes its own URLs (
/tv/1931-disney-s-adventures-of-the-gummi-bears) — and enough of it has reached the catalog to matter. Two different series hit it within a minute on my server.The user-visible cost: a title already in the library never gets linked, so clients keep offering to request something you already own.
Change
The numeric prefix is the identity, so compare on that. Values with no leading digits (
tt0111161), or digits not followed by a separator (12ab), are not TMDB ids and still conflict exactly as before — the fix widens what counts as a match, it does not weaken the conflict check.Applied to both comparisons in
AttachTMDBID: themedia_items.tmdb_idcheck and themedia_item_provider_idsone.Testing
Table test using the real values from the log above, plus the negative cases (different ids must still conflict; non-TMDB identifiers untouched).
go test ./internal/catalog/green.AI-use disclosure
Written by Claude Opus 5 (Claude Code) working with @RXWatcher, who spotted the warning on his server and directed the fix.
Summary by CodeRabbit
Maintainer remediation AI disclosure
Maintainer remediation verification