Skip to content

[Bug] /api/v1/items/reindex endpoint missing session.commit() — new episodes never persisted #1397

Description

@bioengineered

Summary

The /api/v1/items/reindex endpoint successfully fetches new episodes from TVDB and merges them into the session, but never calls session.commit(). The session rolls back on close, so new seasons/episodes are silently lost. The endpoint returns "Successfully re-indexed" even though nothing was persisted.

Steps to Reproduce

  1. Have a show with new episodes available on TVDB that aren't in the Riven database yet
  2. Call POST /api/v1/items/reindex with the show's item_id
  3. API returns {"message": "Successfully re-indexed <show>"}
  4. Check the database — no new episodes were added

Root Cause

In src/routers/secure/items.py, the reindex endpoint calls apply_item_mutation() but never follows it with session.commit(). Every other caller of apply_item_mutation in the same file does call session.commit() immediately after. The function's own docstring states: "Caller is responsible for session.commit()."

The scheduler's _run_reindex_for_item performs the same operation and does commit — so the scheduler path works correctly. Only the API endpoint is affected.

Relevant Code

src/routers/secure/items.py — the reindex handler (around line 1356):

            apply_item_mutation(
                program=di[Program],
                session=session,
                item=item,
                mutation_fn=mutation,
                bubble_parents=True,
            )

            # <-- session.commit() missing here

            logger.info(f"Successfully re-indexed {item.log_string}")

Compare with every other apply_item_mutation caller in the same file, which all have session.commit() after.

Fix

Add session.commit() between apply_item_mutation(...) and the logger.info(...) line, matching the pattern used by all other callers.

Environment

  • Riven v1.0.0 (spoked/riven:dev, image built 2026-04-11)
  • PostgreSQL 17 Alpine

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