Skip to content

[BUG] Server panics with "PrimaryKey is not set" when a custom scan regenerates metadata #1407

Description

@omegaatt36

Description of the Bug

The server process aborts when a library scan runs a custom visit that regenerates metadata. A custom visit is the scan mode that only rebuilds selected parts of a book instead of the whole record. The panic comes from sea-orm. The process exits, so the HTTP server stops and the web app shows a 503 error.

The cause is in handle_book_visit_operation in core/src/filesystem/scanner/utils.rs. The metadata branch builds a media_metadata::ActiveModel, sets only media_id, and then calls ActiveModel::update():

let active_model = media_metadata::ActiveModel {
    media_id: Set(Some(custom.id.clone())),
    ..meta.into_active_model()
};
let updated_meta = active_model.update(&txn).await?;

The primary key of media_metadata is a different column:

#[sea_orm(primary_key, auto_increment = true)]
pub id: i32,

The value in meta comes from ProcessedMediaMetadata, which the scanner builds from the file on disk. That value carries no database id. sea-orm requires the primary key for ActiveModel::update(), so it panics at update.rs:99.

The panic runs on the main thread and nothing catches it. The result is a full process abort, not a failed job.

The other two scan paths do not have this problem:

  1. The hash branch of the same function uses update_many() with an explicit filter. That call does not need the primary key.
  2. The force rebuild path goes through update_media(), which writes the metadata with insert().on_conflict().

Expected Behavior

The scan updates the metadata rows and finishes. If the update fails, the job records the error and the server keeps running.

Steps To Reproduce

  1. Open the settings page of a library that already contains books.
  2. Click Configure scan.
  3. Turn on the option that regenerates metadata.
  4. Start the scan.
  5. The server process exits about one second later. The web app shows Request failed with status code 503.

A process manager can restart the server, but every new scan with the same option stops it again. A scan with only the hash option enabled completes without a problem, which matches the code paths above.

Where is this issue happening?

  • Server
  • Web App

Server & Client Details

Server Details:

  • Release Channel: latest
  • Server OS: openSUSE MicroOS
  • Using Docker: Yes, on Kubernetes, image aaronleopold/stump:0.1.7
  • Server Version: 0.1.7

Client Details:

  • Device: PC
  • OS: Linux
  • Browser: Not Applicable. The server exits before it answers, so every client sees the same 503.

Additional context

Server log for one occurrence:

2026-09-10T14:49:49.038844Z  INFO stump_core::job::run: Starting job, job_id: 4203f1ff-93b4-4b86-b6ab-4b14b0448d61, job_name: "library_scan"
    at core/src/job/run.rs:96

thread 'main' (1) panicked at /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/sea-orm-1.1.16/src/query/update.rs:99:40:
PrimaryKey is not set
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The container exited with code 139 and the orchestrator restarted it.

The same code is present on main at the time of this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions