Skip to content

UpdateEpisodeLink fails on every call: invalid CTE reference without RETURNING #320

Closed

Description

@Quick104

Summary

FileRepository.UpdateEpisodeLink (internal/scanner/file_repo.go) runs a statement whose final SELECT COUNT(*) FROM inserted references a data-modifying CTE that has no RETURNING clause. PostgreSQL rejects this unconditionally with ERROR: WITH query "inserted" does not have a RETURNING clause (SQLSTATE 0A000), so every call fails at runtime, on every PostgreSQL version.

Introduced by #283 (Latest Episodes sort). Invisible because the only caller (internal/metadata/service.go, episode file linking) logs a warning and continues, and no CI runs database-backed Go tests.

Impact

The metadata-side single-file episode relink path has silently done nothing since #283: media_files.episode_id / season/episode numbers are not updated, the episode_libraries row is not inserted, and latest_episode_added_at is not bumped through this path. Bulk linking (BulkLinkEpisodesBySeries, which uses the correct CTE pattern) still works, which masked the breakage.

Reproduction

Run go test ./internal/scanner/ -run TestEpisodeLinkMaintainsLatestEpisodeAdded with SILO_TEST_DATABASE_URL pointing at a migrated scratch database — fails at episode_added_denorm_test.go:104 with the error above.

Fix

Make the INSERT … ON CONFLICT DO NOTHING the top-level statement of the WITH; the count was unused. Discovered while running the DB suites for #319.

Activity

  1. added 2 commits that reference this issue on Jul 6, 2026
    1c8084c
    885354e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions