Repository navigation
fix(scanner): repair invalid CTE that made UpdateEpisodeLink fail on every call - #321
Conversation
…every call The statement ended with SELECT COUNT(*) FROM inserted, but the inserted CTE has no RETURNING clause — PostgreSQL rejects referencing such a CTE (SQLSTATE 0A000), so every UpdateEpisodeLink call has errored since #283. The sole caller logs a warning and continues, so the metadata-side single-file episode relink silently did nothing: episode_id stayed stale, episode_libraries rows were not inserted, latest_episode_added_at was not bumped. Bulk linking uses the correct pattern and masked the breakage. The INSERT is now the top-level statement; the count was unused. Verified against a migrated PostgreSQL scratch database: TestEpisodeLinkMaintainsLatestEpisodeAdded fails on main with the exact error and passes with this change. Fixes #320 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFixed a SQL statement bug in ChangesUpdateEpisodeLink SQL Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Related issues: Suggested labels: bug, database Suggested reviewers: none identified from provided context Poem A CTE once tried to count and fail, ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…every call (#321) The statement ended with SELECT COUNT(*) FROM inserted, but the inserted CTE has no RETURNING clause — PostgreSQL rejects referencing such a CTE (SQLSTATE 0A000), so every UpdateEpisodeLink call has errored since #283. The sole caller logs a warning and continues, so the metadata-side single-file episode relink silently did nothing: episode_id stayed stale, episode_libraries rows were not inserted, latest_episode_added_at was not bumped. Bulk linking uses the correct pattern and masked the breakage. The INSERT is now the top-level statement; the count was unused. Verified against a migrated PostgreSQL scratch database: TestEpisodeLinkMaintainsLatestEpisodeAdded fails on main with the exact error and passes with this change. Fixes #320 Co-authored-by: Claude Fable 5 <[email protected]>
Fixes #320.
Problem
UpdateEpisodeLinkends its update+insert statement withSELECT COUNT(*) FROM inserted, but theinsertedCTE has noRETURNINGclause. PostgreSQL rejects referencing a data-modifying CTE withoutRETURNING(SQLSTATE 0A000), so every call has failed at runtime since #283. The sole caller (internal/metadata/service.goepisode file linking) logs a warning and continues, so the metadata-side single-file relink silently did nothing:media_files.episode_idstayed stale,episode_librariesrows were never inserted, andlatest_episode_added_atnever bumped through this path.BulkLinkEpisodesBySeriesuses the correct CTE pattern (itsinsertedCTE hasRETURNING), which masked the breakage.Fix
Make the
INSERT … ON CONFLICT DO NOTHINGthe top-level statement of theWITH; the trailing count was unused. One statement, identical semantics, now valid SQL.Verification
Against a migrated PostgreSQL scratch database:
TestEpisodeLinkMaintainsLatestEpisodeAdded(the existing skip-gated DB test atepisode_added_denorm_test.go) fails on main with the exact production error and passes with this change — verified in both directions.go build ./..., the scanner unit suite, andgolangci-lint --new-from-rev=origin/mainare clean. No CI runs DB-backed Go tests, which is why this survived since #283; worth considering a self-hosted DB test job as follow-up.Found while running the database suites for #319.
AI-use disclosure
Diagnosed and fixed with Claude Code (Claude Fable 5); human-directed.
🤖 Generated with Claude Code
Summary by CodeRabbit