Repository navigation
fix(collections): reject unknown collection_type on admin create and update - #2450
Conversation
…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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Resolved: the Evidence section now includes before-and-after response excerpts for the same invalid Original requestThe admin API response changes from |
|
Thanks. The Evidence section now has before-and-after responses for the same requests on
Each excerpt shows the status and the changed error fields, with |
…type-validation # Conflicts: # internal/api/handlers/admin_collections_service.go # internal/catalog/collection_type.go
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
left a comment
There was a problem hiding this comment.
🤖 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]>
|
🤖 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
Verification
Left for maintainers
Validated features: none affected. I couldn't read the validation board (this token lacks User manual: unaffected. siloserver.org doesn't document 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)
|
Problem
Closes #2418
Related issue: N/A
Validation tasks: none
Creating or updating an admin collection with a
collection_typethe server doesn't know, such as"bogus", returns500 internal_error. Since #2586 retired Trakt,"trakt"does too. The value goes straight to the database and fails thelibrary_collections_collection_type_checkconstraint. 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 handlesvisibility.Approach
The admin collection service checks
collection_typeon create and update. An unknown value gets acollection_typefield error that lists the allowed types:422 validation_failedon/api/v2/admin/collections. The create check runs innormalizeAdminCollectionInput, which backup restore also runs throughCheckRestoredCollection, so a restore set carrying an unknown type is refused when the restore is planned instead of failing when it is written.manual,smart,mdblist,tmdb. It lives ininternal/catalog/collection_type.gonext to the other collection-type helpers.traktgets the same field error as any other unknown type.collection_typeasmanual. An update has no default to fall back to, so an explicit empty value is refused too (it also returned 500 before). Mapping it tomanualwould 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
trakton the v2 route, an empty type on update, every accepted type, a create that omits the type, and a restored collection withtrakt. Onmainthe 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 intonormalizeAdminCollectionInput.main(which retired/api/v1, feat(api)!: retire /api/v1 behind a 410 tombstone #3200, and removed the v1 route test's handlers), theinternal/api/handlers,internal/apiv2,internal/catalog, andinternal/backuptests pass at 5c0dc49.gofmt,go vet,make test-go, everyverify-*target, web lint, format, build, bundle budget andmake test-web(893 test files) pass on the branch merged with currentmain.make lint-changedwith golangci-lint v2.12.2: 0 issues.mainand on this branch. The test collections were deleted afterwards.Evidence
Surface and build: native API
/api/v2on a test deployment. Before:mainat 9cc3091, which includes #2586. After: this branch at 4f937c0, merged with thatmain.The same requests on both builds. The update requests target a collection newly created with no
collection_type({id}), and send a currentIf-Matchon v2:POST /api/v2/admin/collections,"collection_type":"bogus"500422body.collection_type: collection_type must be manual, smart, mdblist, or tmdbPOST /api/v2/admin/collections,"collection_type":"trakt"500422PATCH /api/v2/admin/collections/{id},"collection_type":"bogus"500422PATCH /api/v2/admin/collections/{id},"collection_type":"trakt"500422PATCH /api/v2/admin/collections/{id},"collection_type":""500422POST /api/v2/admin/collectionswith nocollection_type201,manual201,manualPATCH /api/v2/admin/collections/{id},"collection_type":"smart"200200Before, the five v2 requests (
instanceremoved):{ "type": "https://siloserver.org/docs/api/v2/problems/internal_error", "status": 500, "detail": "An unexpected error occurred." }After, the five v2 requests (
instanceremoved):{ "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/v1has since been retired to410 Goneonmain(#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, includingtrakt, 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
AI Disclosure
/code-reviewat 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 tointernal/catalog). Left as is: the repository-level CHECK mapping and an OpenAPI enum forcollection_type(both broader than this fix), and the v1 400-before-404 order (it matchesvisibility). After feat!: drop Trakt support #2586 merged, the merge withmaindroppedtraktfrom 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-reviewrun. No review by a different model.main, removed the retired v1 route test, and moved the create check intonormalizeAdminCollectionInputso backup restore applies it. A cross-provider review by Codex (gpt-6.1-sol) found nothing further.Note
Reject unknown
collection_typeon admin collection create and updatevalidateCollectionTypeandcatalog.IsKnownType, which accept onlymanual,smart,mdblist, andtmdb.collection_typefield error.smartstring incatalog.IsLiveQueryTypewith the newcollectionTypeSmartconstant.trakttype is now rejected on create, update, and restore paths; checkupdateAdminCollectionin admin_collections_service.go for consumers still sendingtrakt.Macroscope summarized 5c0dc49.