Repository navigation
fix(metadata): tolerate missing content item when recording stale IDs - #37
Conversation
StaleMediaIDRepository.Upsert inserts (content_id, provider, ...) into stale_media_ids, which has a foreign key to media_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a 23503 foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs. When the referenced item no longer exists there is nothing left to track, so treat that specific FK violation as a logged no-op (at Info, with provider_id, so a deletion wave stays visible). Other errors still propagate. The swallow decision is extracted to resolveStaleUpsertError so it is unit-testable without a database, and the pgconn error-classification boilerplate is consolidated into a shared isPgConstraintViolation helper that isProviderIDUniqueConflict now also uses. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR centralizes PostgreSQL constraint violation detection into a reusable helper function ( ChangesPostgreSQL Error Handling Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…Silo-Server#37) StaleMediaIDRepository.Upsert inserts (content_id, provider, ...) into stale_media_ids, which has a foreign key to media_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a 23503 foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs. When the referenced item no longer exists there is nothing left to track, so treat that specific FK violation as a logged no-op (at Info, with provider_id, so a deletion wave stays visible). Other errors still propagate. The swallow decision is extracted to resolveStaleUpsertError so it is unit-testable without a database, and the pgconn error-classification boilerplate is consolidated into a shared isPgConstraintViolation helper that isProviderIDUniqueConflict now also uses. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…#37) StaleMediaIDRepository.Upsert inserts (content_id, provider, ...) into stale_media_ids, which has a foreign key to media_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a 23503 foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs. When the referenced item no longer exists there is nothing left to track, so treat that specific FK violation as a logged no-op (at Info, with provider_id, so a deletion wave stays visible). Other errors still propagate. The swallow decision is extracted to resolveStaleUpsertError so it is unit-testable without a database, and the pgconn error-classification boilerplate is consolidated into a shared isPgConstraintViolation helper that isProviderIDUniqueConflict now also uses. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…#37) StaleMediaIDRepository.Upsert inserts (content_id, provider, ...) into stale_media_ids, which has a foreign key to media_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a 23503 foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs. When the referenced item no longer exists there is nothing left to track, so treat that specific FK violation as a logged no-op (at Info, with provider_id, so a deletion wave stays visible). Other errors still propagate. The swallow decision is extracted to resolveStaleUpsertError so it is unit-testable without a database, and the pgconn error-classification boilerplate is consolidated into a shared isPgConstraintViolation helper that isProviderIDUniqueConflict now also uses. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…#37) StaleMediaIDRepository.Upsert inserts (content_id, provider, ...) into stale_media_ids, which has a foreign key to media_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a 23503 foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs. When the referenced item no longer exists there is nothing left to track, so treat that specific FK violation as a logged no-op (at Info, with provider_id, so a deletion wave stays visible). Other errors still propagate. The swallow decision is extracted to resolveStaleUpsertError so it is unit-testable without a database, and the pgconn error-classification boilerplate is consolidated into a shared isPgConstraintViolation helper that isProviderIDUniqueConflict now also uses. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Problem
StaleMediaIDRepository.Upsertinserts(content_id, provider, ...)intostale_media_ids, which has a foreign key tomedia_items.content_id. A metadata refresh can start for an item that is then deleted or merged away (e.g. by provider-ID canonicalization) before the provider 404 lands and triggers the upsert. The parent row is gone by then, so the insert fails with a23503foreign-key violation (stale_media_ids_content_id_fkey) and the refresh surfaces a spurious error — observed in production postgres logs.Approach
Info, withprovider_id, so a deletion wave stays visible). All other errors still propagate.resolveStaleUpsertErrorso it is unit-testable without a database.errors.As(&pgconn.PgError)+Code/ConstraintNameboilerplate is consolidated into a sharedisPgConstraintViolationhelper that the existingisProviderIDUniqueConflictnow also uses.Risks / follow-up
Low. The swallow is narrowly scoped to
23503onstale_media_ids_content_id_fkey; unique violations and other FKs still surface. The constraint name is the Postgres-auto-generated name frommigrations/036(documented at the call site). A companion PR (record-stale-IDs-against-canonical-item) reduces how often this race fires by recording against the surviving canonical item.Verification
go test ./internal/metadata/andgo vet ./internal/metadata/pass. New tests cover the classifier and the swallow-vs-propagate decision (nil / FK / other-pg-error / generic).AI-use disclosure
Implemented with Claude Code (Opus 4.8), TDD, after a multi-agent review of the change.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests