Skip to content

fix(collections): reject unknown collection_type on admin create and update - #2450

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
bulderi:fix/admin-collection-type-validation
Nov 13, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
bulderi:fix/admin-collection-type-validation

Conversation

@bulderi

@bulderi bulderi commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2418
Related issue: N/A
Validation tasks: none

Creating or updating an admin collection with a collection_type the server doesn't know, such as "bogus", returns 500 internal_error. Since #2586 retired Trakt, "trakt" does too. The value goes straight to the database and fails the library_collections_collection_type_check constraint. The web admin only sends known types, so this hits API clients and scripts. With this change the request is refused with a field error before any database access, the same way #1667 handles visibility.

Approach

The admin collection service checks collection_type on create and update. An unknown value gets a collection_type field error that lists the allowed types: 422 validation_failed on /api/v2/admin/collections. The create check runs in normalizeAdminCollectionInput, which backup restore also runs through CheckRestoredCollection, so a restore set carrying an unknown type is refused when the restore is planned instead of failing when it is written.

  • The accepted set is the one the CHECK constraint allows since feat!: drop Trakt support #2586: manual, smart, mdblist, tmdb. It lives in internal/catalog/collection_type.go next to the other collection-type helpers. trakt gets the same field error as any other unknown type.
  • Create still treats a missing collection_type as manual. An update has no default to fall back to, so an explicit empty value is refused too (it also returned 500 before). Mapping it to manual would silently turn a smart or imported collection into a manual one.

There is no OpenAPI change. The Apple and Android clients don't call the admin collection routes. jellycompat has no admin collection writes.

Validation

  • Unit and route tests cover create and update with an unknown type and with trakt on the v2 route, an empty type on update, every accepted type, a create that omits the type, and a restored collection with trakt. On main the v2 route test fails because the request reaches the repository and the route returns 500. The restore row fails on 76b8c04, before the check moved into normalizeAdminCollectionInput.
  • After merging current main (which retired /api/v1, feat(api)!: retire /api/v1 behind a 410 tombstone #3200, and removed the v1 route test's handlers), the internal/api/handlers, internal/apiv2, internal/catalog, and internal/backup tests pass at 5c0dc49.
  • Full gate from CONTRIBUTING.md in Linux containers (Go 1.26, Node 22): build, gofmt, go vet, make test-go, every verify-* target, web lint, format, build, bundle budget and make test-web (893 test files) pass on the branch merged with current main.
  • make lint-changed with golangci-lint v2.12.2: 0 issues.
  • Test deployment: the requests in Evidence, on main and on this branch. The test collections were deleted afterwards.

Evidence

Surface and build: native API /api/v2 on a test deployment. Before: main at 9cc3091, which includes #2586. After: this branch at 4f937c0, merged with that main.

The same requests on both builds. The update requests target a collection newly created with no collection_type ({id}), and send a current If-Match on v2:

Request Before After After error
POST /api/v2/admin/collections, "collection_type":"bogus" 500 422 body.collection_type: collection_type must be manual, smart, mdblist, or tmdb
POST /api/v2/admin/collections, "collection_type":"trakt" 500 422 same
PATCH /api/v2/admin/collections/{id}, "collection_type":"bogus" 500 422 same
PATCH /api/v2/admin/collections/{id}, "collection_type":"trakt" 500 422 same
PATCH /api/v2/admin/collections/{id}, "collection_type":"" 500 422 same
POST /api/v2/admin/collections with no collection_type 201, manual 201, manual none
PATCH /api/v2/admin/collections/{id}, "collection_type":"smart" 200 200 none

Before, the five v2 requests (instance removed):

{
  "type": "https://siloserver.org/docs/api/v2/problems/internal_error",
  "status": 500,
  "detail": "An unexpected error occurred."
}

After, the five v2 requests (instance removed):

{
  "type": "https://siloserver.org/docs/api/v2/problems/validation_failed",
  "status": 422,
  "detail": "The request did not pass validation; see errors.",
  "errors": [
    {
      "location": "body.collection_type",
      "code": "invalid",
      "detail": "collection_type must be manual, smart, mdblist, or tmdb"
    }
  ]
}

/api/v1 has since been retired to 410 Gone on main (#3200), so this branch no longer changes any v1 response; the v1 rows recorded on the builds above were removed from this table.

Risks

A client that sent an unknown collection_type, including trakt, now gets 422 instead of 500. A restore set carrying an unknown type is refused when the restore is planned. Not changed here: the repository still reports any CHECK violation as a generic error.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (Claude desktop app, Code tab)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted
  • Adversarial review: /code-review at high effort (claude-opus-5-5) over the branch diff, followed by the repository's pre-PR checklist (callers, existing stored values, mixed versions, validation tasks). It found six items. Fixed: a missing test for a create without a type, a doc comment that misdescribed the create path, and the accepted-type list duplicated in the handler (moved to internal/catalog). Left as is: the repository-level CHECK mapping and an OpenAPI enum for collection_type (both broader than this fix), and the v1 400-before-404 order (it matches visibility). After feat!: drop Trakt support #2586 merged, the merge with main dropped trakt from the accepted set; that conflict resolution was checked by reading it against feat!: drop Trakt support #2586 and by the tests and gate above, not by a second /code-review run. No review by a different model.
  • Maintainer review: Claude Code (claude-opus-5-5) merged current main, removed the retired v1 route test, and moved the create check into normalizeAdminCollectionInput so backup restore applies it. A cross-provider review by Codex (gpt-6.1-sol) found nothing further.

Note

Reject unknown collection_type on admin collection create and update

  • Adds validateCollectionType and catalog.IsKnownType, which accept only manual, smart, mdblist, and tmdb.
  • Admin create validates the type when nonempty; admin update validates any provided type, including empty, before looking up the collection. Invalid values return a collection_type field error.
  • Replaces the hard-coded smart string in catalog.IsLiveQueryType with the new collectionTypeSmart constant.
  • Risk: retired trakt type is now rejected on create, update, and restore paths; check updateAdminCollection in admin_collections_service.go for consumers still sending trakt.

Macroscope summarized 5c0dc49.

…update

An unknown collection_type reached the library_collections CHECK
constraint and surfaced as a 500 on both the v2 and v1 admin collection
routes. Validate it in the shared service and return a collection_type
field error instead: 422 validation_failed on v2, 400 on v1. An update
that sends an empty collection_type is refused too, since an update has
no default type to fall back to.

Closes Silo-Server#2418
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Admin collection creation and updates now validate collection types against known catalog values. Invalid types return a collection_type validation error. Tests cover service behavior, API responses, and rejection of a restored collection with the retired trakt type.

Changes: Admin collection type validation

Layer / File(s) Summary
Define known collection types
internal/catalog/collection_type.go
The catalog adds IsKnownType for manual, smart, MDBList, and TMDB values. IsLiveQueryType now uses the smart type constant.
Validate admin collection requests
internal/api/handlers/admin_collections_service.go, internal/api/handlers/admin_collections_service_test.go, internal/apiv2/admin_collections_test.go, internal/api/handlers/library_restored_test.go
Creation validates nonempty types; an omitted type keeps its existing default handling. Updates validate every supplied type, including an empty value. Tests cover supported and unsupported types, API validation responses, and rejection of a restored collection with type trakt.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: Minimal · up to 5c0dc

Admin collection create and update now return a field-level validation error for unknown collection types instead of a server error. Existing defaults for omitted create types are preserved, and no merge-blocking risk remains.

Security architecture risk: Minimal · up to 5c0dc

The change rejects unsupported collection types earlier without widening administrative access or weakening database constraints. Creation keeps its existing default, while updates reject explicit empty values. Backups containing retired collection types are now refused before collection writes.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed control affects administrator-supplied collection metadata and restore entries targeting shared library collections. It narrows accepted input without granting authority over additional collections, accounts, services or credentials.

Trust Boundaries and Controls

  • observed — The new field validation does not replace update concurrency controls. The HTTP update handler obtains and checks the collection validator before calling the service, and the service forwards the expected revision to the repository alongside the validated type.

Resilience and Maintainability Implications

  • inferred — The added type check is deterministic and has no side effects. Rejected admin requests cannot reach collection mutation or artwork processing, and rejected restore entries exit before collection creation or membership changes. Repetition, interruption or concurrent requests do not introduce a new intermediate state through this validation gate.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: admin collection create and update now reject unknown collection_type values. It uses the conventional fix(scope) form and matches the changeset (validateCollectionTyp…
Description check Passed The description covers the problem, the approach, validation steps, evidence tables, risks, and AI disclosure. It matches the changeset: the accepted-type set in internal/catalog, the create check in …
Linked Issues check Passed Issue #2418 requires that admin collection create and update reject an unknown collection_type with a 422 validation_failed field error on /api/v2 that lists the allowed values, and never return 500 f…
Out of Scope Changes check Passed The changes stay within admin collection-type validation. They include the create and update check in internal/api/handlers/admin_collections_service.go, the IsKnownType helper and collectionTypeSmart…
Full details: Title check

Explanation

The title names the main change: admin collection create and update now reject unknown collection_type values. It uses the conventional fix(scope) form and matches the changeset (validateCollectionType, IsKnownType, the 422 field error). It is specific and does not rely on vague terms.

Full details: Description check

Explanation

The description covers the problem, the approach, validation steps, evidence tables, risks, and AI disclosure. It matches the changeset: the accepted-type set in internal/catalog, the create check in normalizeAdminCollectionInput, the update validation, the restore path, and the trakt removal. It is far from off-topic.

Full details: Linked Issues check

Explanation

Issue #2418 requires that admin collection create and update reject an unknown collection_type with a 422 validation_failed field error on /api/v2 that lists the allowed values, and never return 500 from the CHECK constraint. At head, internal/catalog/collection_type.go defines IsKnownType, which accepts exactly manual, smart, mdblist, and tmdb. The handler checks this before repo.Create or repo.Update, and the restore path (CheckRestoredCollection via normalizeAdminCollectionInput) applies the same check. The v2 test set covers bogus and empty values on update, and the PR's before/after evidence shows 500 on main changing to 422 with body.collection_type on the branch for bogus, trakt, and empty update values.

The issue lists trakt as an allowed value, but it was written before #2586. The PR states that #2586 removed trakt from the CHECK constraint. The main-build evidence (trakt returns 500 on 9cc3091, which includes #2586) is consistent with that. The migration history was not read directly in this review. The v1 bridge requirement (400 field error) is superseded: the PR states /api/v1 is retired to 410 Gone on main (#3200). That retirement was not verified in this review.

Full details: Out of Scope Changes check

Explanation

The changes stay within admin collection-type validation. They include the create and update check in internal/api/handlers/admin_collections_service.go, the IsKnownType helper and collectionTypeSmart constant in internal/catalog/collection_type.go, the restore check through normalizeAdminCollectionInput, and the related tests (handler, v2 route, and restored-collection trakt case). The IsLiveQueryType change replaces a literal with a constant and keeps its trimming and case-insensitive comparison. The latest commit adds restore coverage for the same validation. No OpenAPI change or unrelated product behavior appears in the reviewed evidence.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 732b24aa-9bae-4ae3-816c-c6c75d9352f4
Commits

Reviewing files that changed from the base of the PR and between 76b8c04 and 5c0dc49.

Files selected for processing: 2

  • internal/api/handlers/admin_collections_service.go
  • internal/api/handlers/library_restored_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 14, 2026
@silo-triage

silo-triage Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Resolved: the Evidence section now includes before-and-after response excerpts for the same invalid collection_type requests on v2 and the v1 bridge, with build identifiers, status codes, and changed error fields.

Original request

The admin API response changes from 500 internal_error to a field validation error, so the no-visible-change statement does not fit CONTRIBUTING.md's server-response evidence rule. Please add redacted before-and-after response excerpts for the same invalid collection_type request on v2 and the v1 bridge, naming each build or commit. Include the status and changed error fields; UI screenshots are not needed.

@bulderi

bulderi commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. The Evidence section now has before-and-after responses for the same requests on main at 6144c45 and on this branch at 3cd313d, both on a test deployment:

  • v2 POST /api/v2/admin/collections and PATCH /api/v2/admin/collections/{id} with "collection_type":"bogus", plus PATCH with "": 500 internal_error before, 422 validation_failed after, with the error at body.collection_type.
  • v1 bridge POST /api/v1/admin/collections and PUT /api/v1/admin/collections/{id} with "collection_type":"bogus": 500 internal_error before, 400 bad_request after.

Each excerpt shows the status and the changed error fields, with instance removed. A create without collection_type and a change to smart answer the same on both builds.

@Quick104 Quick104 mentioned this pull request Oct 16, 2026
3 tasks
…type-validation

# Conflicts:
#	internal/api/handlers/admin_collections_service.go
#	internal/catalog/collection_type.go
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 16, 2026
@silo-triage silo-triage Bot removed the evidence-required Needs before-and-after evidence before the Evidence check passes label Nov 12, 2026
Main retired the /api/v1 bridge (Silo-Server#3200), so the v1 route test for
collection_type is gone with the handlers it called. Main also removed
TestCollectionProblemRendersInvalidArtworkAsValidationProblem (Silo-Server#2817);
the conflict keeps that removal and this branch's v2 test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code (claude-opus-5-5)

I merged current main into this branch (76b8c04) before reviewing. Main retired the /api/v1 bridge in #3200, so the v1 route test went with the handlers it called. I resolved the one conflict in internal/apiv2/admin_collections_test.go by keeping your v2 test and the removal #2817 made. One finding is below.

A backup restore checks a collection through CheckRestoredCollection,
which runs normalizeAdminCollectionInput and promises to refuse what the
editor refuses. The create-side collection_type check sat outside that
function, so a restore set carrying a retired or unknown type passed the
planner and then failed on the CHECK constraint when written. Move the
check into normalizeAdminCollectionInput, where create and restore both
run it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104

Copy link
Copy Markdown
Contributor

🤖 Claude Code (claude-opus-5-5)

Review summary at 5c0dc49: this fixes a real 500, and the branch is ready to land once CI passes.

What changed during review

  • Merged current main (76b8c04). Main retired /api/v1 to 410 Gone (feat(api)!: retire /api/v1 behind a 410 tombstone #3200), so the v1 route test went with the handlers it called. The v2 fix still applies unchanged. In the conflict in internal/apiv2/admin_collections_test.go, I kept this branch's v2 test and the test removal from test: remove low-value and never-run tests #2817.
  • Fixed the one finding (5c0dc49): the create-side collection_type check now runs in normalizeAdminCollectionInput, so backup restore (CheckRestoredCollection) refuses an unknown type as the editor does. The update path is unchanged. The PR body now reflects both changes and no longer claims v1 behavior.

Verification

  • TestAdminCollectionsRejectUnknownCollectionType (v2 route) fails on main: the create reaches the repository and the route answers 500. It passes on this branch.
  • The new trakt row in TestRestoredEntriesMeetTheEditorChecks failed on 76b8c04 and passes at 5c0dc49.
  • The internal/api/handlers, internal/apiv2, internal/catalog, and internal/backup tests pass locally. The handler-level service test calls a helper this PR adds, so it can't run against main.
  • Not reproduced live in this review. The evidence page's v2 responses were recorded on the builds it names. Moving the create check doesn't change any response it quotes, because those requests carry a title and a library.
  • A cross-provider review (Codex, gpt-6.1-sol) of 76b8c04 found the same restore gap and nothing else.

Left for maintainers

  • The v2 schema still types collection_type as a free string on admin create and update (internal/apiv2/admin_collection_types.go). The personal-collections input already declares enum:"manual,smart". Declaring the four accepted values before /api/v2 locks would publish the rule; doing it after the lock narrows a published type. Not required for this fix.
  • fix(collections): refuse a taken collection name instead of failing with a 500 #3933 edits other hunks in admin_collections_service.go; whichever lands second may need a small merge.

Validated features: none affected. I couldn't read the validation board (this token lacks read:project). From the Validation issues' bodies, the passed cases in #193 (S1–S7) and #194 (A2–A5) send only accepted types or don't reach this code. Validation tasks: none still holds.

User manual: unaffected. siloserver.org doesn't document collection_type or the admin collection API.

Other clients: N/A. Apple, Android, and Roku don't call the admin collection routes, and the web admin sends only accepted types. jellycompat has no admin collection writes.

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: it turns a database failure on bad admin input into the same field error visibility already returns, at the service boundary both the API and restore share, with no new surface area.
  • Readiness: the route test fails on main and passes here, the restore gap is closed with a test that failed before the fix, and no passed validation case is touched.

@Quick104
Quick104 merged commit a12425f into Silo-Server:main Nov 13, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Admin collection create and update return 500 for an unknown collection_type

2 participants