Skip to content

[bug] Admin collection create and update return 500 for an unknown visibility value #1650

Description

@Quick104

What happened

Creating or updating an admin library collection with a visibility value other than visible or hidden returns 500 internal_error instead of a validation error. The collection is not created or changed. API clients get no hint that the field is the problem.

Steps to reproduce

On an isolated test deployment, as an admin:

  1. POST /api/v2/admin/collections with {"title":"repro","library_id":"1","visibility":"public"}. Response: 500, problem type internal_error.
  2. PATCH /api/v2/admin/collections/{id} on an existing collection, with a valid If-Match and {"visibility":"public"}. Response: 500, problem type internal_error.

The same body without visibility, or with "visible", succeeds.

Expected behavior

Both requests return 422 validation_failed with an error on visibility, and list the allowed values (visible, hidden).

Silo version / commit

Reproduced on a build of d57c7c1 (PR #1326, based on main at 9a730f2b). The handler code involved is unchanged on main at f84d2dee.

Deployment

Local dev build (isolated sandbox with Postgres and S3-compatible storage).

Clients affected

Other/not client-specific. The web UI only sends visible or hidden, so this affects API clients that send another value.

Relevant logs

The server logs only the request line; the underlying database error is not logged.

level=INFO msg="apiv2 request" component=apiv2 request_id=718db1a72ab5dc1aae0da261 api_major=2 operation_id=createAdminCollection method=POST path_pattern=/api/v2/admin/collections status=500 status_class=5xx error_code=internal_error auth_class=session duration_ms=2 client_ip=<redacted> user_id=1
level=INFO msg="apiv2 request" component=apiv2 request_id=cb39d8f24a5f5981ecb18d80 api_major=2 operation_id=updateAdminCollection method=PATCH path_pattern=/api/v2/admin/collections/{id} status=500 status_class=5xx error_code=internal_error auth_class=session duration_ms=5 client_ip=<redacted> user_id=1

Technical notes

  • defaultCollectionVisibility in internal/api/handlers/library_collections.go maps an empty value to visible and passes any other string through. createAdminCollection and updateAdminCollection in internal/api/handlers/admin_collections_service.go send it to the repository unchecked.
  • library_collections has CHECK (visibility IN ('visible','hidden')) (library_collections_visibility_check), so the insert or update fails and the error surfaces as a 500.
  • The v2 OpenAPI schema types visibility as a plain string with no enum, so request validation doesn't catch it either.
  • A likely fix: validate visibility in the handler (or add an enum to the v2 schema) and return a field error. Check the v1 bridge routes, which share these handlers.

AI disclosure

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

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions