Skip to content

fix(apiv2): answer null on a monitor field with 422 naming it - #4064

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
rangoDJ:fix/subscription-null-422-3720
Nov 13, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
rangoDJ:fix/subscription-null-422-3720

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3720
Related issue: #3535
Validation tasks: none

Other clients: Apple N/A (leaves unset fields out of this request, so it never sends null); Android N/A (doesn't call this operation); Roku N/A (same)

PATCH /api/v2/downloads/subscriptions/{id} answered an explicit null on any monitor field (mode, season_numbers, delete_watched, max_storage_bytes, quality, active) with 400 malformed_request and no member name. The v2 PATCH rule in docs/architecture/api-contract.md makes null on a member that can't be cleared a 422 validation_failed naming the member, which is what updateProfile answers.

Dependencies and merge order: no code dependency, and it builds on main. #3535 (open) edits the same handler's schema and adds {"quality":null} to the same test list, which this PR replaces. Whichever merges second needs a small conflict fix in download_subscription_mutations_test.go. #3535's comment on TransformSchema says the handler refuses null "with 400", which would then read 422.

#4074 (#4068) builds on this branch and should merge after it.

Approach

  • The operation's input keeps the raw body, as ProfileUpdateInput does, and the handler checks it with rejectNonNullableNulls, the helper updateProfile uses. No monitor field can be cleared, so every null member gets an error at body.<member>, sorted by location.
  • Other bounds keep their status: max_storage_bytes: -1 still answers 400.
  • The OpenAPI document already lists 422 for this operation, so it doesn't change.

Validation

  • gofmt, go vet, and the changed-package lint are clean.
  • go test passes for internal/apiv2 and internal/contractspec, and make verify-apiv2-openapi reports the document current.
  • TestSubscriptionMutationTransport now expects 422 naming the member for null on each of the six fields, and both members for a body with two nulls. With the old null check put back, it fails with status = 400, want 422.
  • Not run: the request against a running server, and the full make test-go.

Evidence

No visible layout change. The evidence is the response body, from the transport test's handler on WSL2 (Ubuntu, go1.26.4 linux/amd64), main at 0387303d9 and this PR at ab30ed69d. The instance member is left out.

Before (main):

PATCH {"mode":null} -> 400 {"type":"https://siloserver.org/docs/api/v2/problems/malformed_request","title":"Malformed request","status":400,"detail":"Monitor fields cannot be null."}
PATCH {"active":true,"quality":null,"mode":null} -> 400 {"type":"https://siloserver.org/docs/api/v2/problems/malformed_request","title":"Malformed request","status":400,"detail":"Monitor fields cannot be null."}

After (this PR):

PATCH {"mode":null} -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"null is not a value for this member; omit it to leave it unchanged","errors":[{"location":"body.mode","code":"invalid_type","detail":"null is not a value for this member; omit it to leave it unchanged"}]}
PATCH {"active":true,"quality":null,"mode":null} -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"The request did not pass validation; see errors.","errors":[{"location":"body.mode","code":"invalid_type","detail":"null is not a value for this member; omit it to leave it unchanged"},{"location":"body.quality","code":"invalid_type","detail":"null is not a value for this member; omit it to leave it unchanged"}]}
$ go test -count=1 ./internal/apiv2/ ./internal/contractspec/
ok  	github.com/Silo-Server/silo-server/internal/apiv2	108.048s
ok  	github.com/Silo-Server/silo-server/internal/contractspec	2.398s

Risks

  • A client that relied on 400 for a null monitor field now gets 422. No first-party client sends null here, and /api/v2 isn't locked yet.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (Claude desktop app, Code tab)
  • Tool(s): Claude Code; GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Return 422 naming the field when a null value hits a monitor field in apiv2

PATCH requests to download subscriptions previously returned a generic malformed-request problem when a monitor field was null. The handler in download_subscription_mutations.go now keeps the raw request body on DownloadSubscriptionPatchInput and passes it to rejectNonNullableNulls, which reports the offending body members by name.

Transport tests cover null in each monitor field and multi-field cases, asserting locations are reported in order (e.g. body.mode, body.quality).

  • Behavioral Change: null monitor fields now return a 422 validation problem with body locations instead of a generic 400 malformed-request problem.

Macroscope summarized ab30ed6.

PATCH /api/v2/downloads/subscriptions/{id} refused an explicit null on
any monitor field with 400 malformed_request and no member name. The v2
PATCH rule in api-contract.md makes null on a member that cannot be
cleared a 422 validation_failed naming the member, as updateProfile
answers. The handler now checks the raw body with the same helper, so
each null member is named at body.<member>.

Closes Silo-Server#3720

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@silo-kody

silo-kody Bot commented Nov 13, 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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The subscription PATCH input now retains the raw request body. The handler uses it to return member-specific validation errors when non-nullable monitor fields contain null. Transport tests cover individual fields and multiple null fields.

Changes: Subscription null validation

Layer / File(s) Summary
Raw-body null validation
internal/apiv2/download_subscription_mutations.go, internal/apiv2/download_subscription_mutations_test.go
The patch input retains the request body. The handler reports null values at the corresponding member, and tests verify errors for individual fields and for multiple fields. The negative max_storage_bytes test continues to expect HTTP 400.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: Minimal · up to ab30e

Explicit null on the six non-clearable subscription monitor fields now returns a 422 that names each member, as the linked issue requests. No merge-blocking risk remains. Any client that relied on the old 400 response will now see 422, which the PR states is acceptable because /api/v2 is not locked.

Security architecture risk: Low · up to ab30e

The response change is narrow and preserves existing identity, ownership, and concurrency checks. No security regression was demonstrated, but null rejection now depends on retaining the original request body, a dependency that was not independently confirmed for every request path.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The reviewed mutation remains scoped to a subscription selected by subscription ID, user, profile, and device. The service retains catalog-access validation before mutation, and the PATCH registration retains its 128 KiB request-body limit.

Trust Boundaries and Controls

  • inferred — For a correctly populated raw body, duplicate and case-variant member names do not provide a newly accepted null write. A final null that leaves a typed monitor field null also remains visible under an exact key in the raw-member map. Some mixed-case inputs can instead be rejected more strictly than before.

Resilience and Maintainability Implications

  • observed — The unchanged mutation path rechecks conditional-update guards and the prior timestamp under a row lock, then writes within a transaction with deferred rollback. Null rejection occurs before this path and creates no partial database transition. Successful PATCH handling does not initiate episode backfill.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: PATCH on the download subscription endpoint now answers an explicit null on a monitor field with 422 validation_failed that names the member. The title states the fix …
Linked Issues check Passed Directly linked issue #3720 requires that PATCH /api/v2/downloads/subscriptions/{id} return 422 validation_failed, naming the member, when null is sent for any of the six non-clearable monitor fields.…
Out of Scope Changes check Passed The whole-PR changes are limited to internal/apiv2/download_subscription_mutations.go (RawBody field, null-check replacement with rejectNonNullableNulls) and internal/apiv2/download_subscription_mutat…
Description check Passed The description is specific and on-topic. It names the endpoint (PATCH /api/v2/downloads/subscriptions/{id}), the six monitor fields, the old 400 malformed_request behavior and the new 422 validation_…
Full details: Title check

Explanation

The title names the main change: PATCH on the download subscription endpoint now answers an explicit null on a monitor field with 422 validation_failed that names the member. The title states the fix and the status code, matching the changeset summary and objectives.

Full details: Linked Issues check

Explanation

Directly linked issue #3720 requires that PATCH /api/v2/downloads/subscriptions/{id} return 422 validation_failed, naming the member, when null is sent for any of the six non-clearable monitor fields. The reviewed diff of internal/apiv2/download_subscription_mutations.go removes the generic 400 null check. It adds a RawBody []byte field to DownloadSubscriptionPatchInput and calls rejectNonNullableNulls(in.RawBody, nil) in updateDownloadSubscription. The PR description states this helper is the one updateProfile uses, and that it reports one error per null member at body.<member>. The test changes replace the combined null check with per-field cases for all six fields and a two-null case, per the raw summary. The max_storage_bytes and season bounds checks still return 400, as the issue does not require a change there. #3535 is contextual only and adds no requirements. I read the handler diff directly. I did not read the helper body or the test file, so the exact error ordering and the per-member error text rely on the PR description and summary. The tests were reported passing by the author; I did not rerun them.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes are limited to internal/apiv2/download_subscription_mutations.go (RawBody field, null-check replacement with rejectNonNullableNulls) and internal/apiv2/download_subscription_mutations_test.go (null-case coverage for the same operation). The OpenAPI document is unchanged, per the PR description and summary. Each change connects directly to #3720. The new RawBody field follows the existing ProfileUpdateInput pattern that the issue references. No unrelated file or behavior change appears in the reviewed evidence. Residual uncertainty: I did not inspect the full test file diff, so I rely on the summary for its contents.

Full details: Description check

Explanation

The description is specific and on-topic. It names the endpoint (PATCH /api/v2/downloads/subscriptions/{id}), the six monitor fields, the old 400 malformed_request behavior and the new 422 validation_failed behavior. It also explains the approach (raw body, rejectNonNullableNulls helper), lists validation steps and test evidence, and notes a risk for clients that relied on the 400. It describes the changeset in detail, so it passes the lenient check.

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: bd8cdfdb-7144-4895-ae2d-bd0c962f486c
Commits

Reviewing files that changed from the base of the PR and between 7edef3d and ab30ed6.

Files selected for processing: 2

  • internal/apiv2/download_subscription_mutations.go
  • internal/apiv2/download_subscription_mutations_test.go

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

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 13, 2026
@Quick104

Copy link
Copy Markdown
Contributor

Maintainer review

Reviewed head: ab30ed69dc. I found no defects in this change, so I'm not pushing any commits.

Fit: 9/10 · Readiness: 9/10 — ready

  • Fit: The change brings updateDownloadSubscription in line with the settled v2 PATCH rule in docs/architecture/api-contract.md. That rule makes null on a member that can't be cleared a 422 validation_failed naming the member. The change uses the rejectNonNullableNulls helper that updateProfile and the other v2 PATCH handlers already use, instead of adding a second check.
  • Readiness: TestSubscriptionMutationTransport fails on the base with status = 400, want 422 ("Monitor fields cannot be null.") and passes on this head. The OpenAPI document already lists 422 for the operation and doesn't change.

What I checked

  • Probes against the handler on this head: null with an unknown member still gets the schema's 422 unknown_field. null with max_storage_bytes: -1 reports only the null member. null with a missing or stale If-Match answers 422, which is the same precedence the base's 400 had, because the null check runs before the service evaluates the guard. A rejected request never reaches the service or changes the ETag.
  • An independent adversarial review by a second model (Codex, gpt-6.1-sol) on this head covered whitespace, escaped, duplicate and case-variant keys, nested values, body limits, and compression, and found no defects. It found that the generated OpenAPI document stays byte-identical.

Left for the maintainers

Validation, manual, and clients

  • Validated features: none affected. No passed case on the v1.0 board covers the status a monitor edit returns for null. The closest task, Downloads / offline — Server (Downloads / offline — Server #1168), has no results recorded.
  • User manual: unaffected. The change only alters the status of an error response to a malformed request.
  • Other clients: silo-apple sends this PATCH, but it leaves unset fields out of the body and handles any non-200 response the same way, so nothing changes there. silo-android, Roku, and the web app don't call this operation. jellycompat has no equivalent.

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

Quick104 added a commit to blurbery/silo-server that referenced this pull request Nov 13, 2026
Silo-Server#4064 changes the answer to null on a monitor field from 400 to 422, so
the TransformSchema comment and the approval reasons say the handler
refuses null rather than naming the status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 merged commit ce41061 into Silo-Server:main Nov 13, 2026
18 checks passed
Quick104 added a commit to blurbery/silo-server that referenced this pull request Nov 13, 2026
…patch-nullability

Silo-Server#4064 answers null on a monitor field with 422 naming the member and
covers all six fields, quality included, in its own transport test, so
the transport test takes main's side and this branch no longer lists
{"quality":null} among the 400 cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rangoDJ added a commit to rangoDJ/silo-server that referenced this pull request Nov 13, 2026
Silo-Server#4064 merged as ce41061, a squash of ab30ed6, which this branch was
built on. The two conflicted in the subscription handler and its test;
this branch's side keeps Silo-Server#4064's null check and adds the bounds check.
main's copy of the files equals ab30ed6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104 added a commit that referenced this pull request Nov 14, 2026
)

* fix(apiv2): list null in the enum of nullable request members

JSON Schema 2020-12 applies type and enum separately, so a member typed
["string", "null"] whose enum lists only strings still refuses null.
ProfileUpdate.max_playback_quality (null removes the ceiling) and
AdminItemMetadataUpdate.status (null leaves it unchanged) were documented
that way, so a client that validates against /api/v2 refused a null the
server accepts.

GenerateOpenAPI now adds null to the enum of every nullable component
schema after registration, which replaces the per-type transformer on
AdminPlaybackHistoryEntry. The pass runs on the document only: Huma's
validator accepts null on a nullable schema before it checks the enum,
and the registered enum stays as it was, so the 422 message for a bad
value doesn't gain a null.

DownloadSubscriptionPatchBody.quality is held out through
apiv2.NullEnumWithheld: Patch documents it as nullable, but the handler
answers 400 for null on every monitor field.

The spec lint now fails a nullable enum without null, and fails a
NullEnumWithheld entry once its member no longer needs it.

Closes #2980

* refactor(contractspec): name the component schema prefix once

goconst flags a string literal used three times, and the nullable enum
rule added the third use of "components.schemas.". The contract doc
now says which locations the lint checks: members and array items.

* fix(apiv2): stop documenting the monitor patch fields as nullable

Patch documents every member as nullable, so the updateDownloadSubscription
body advertised null for mode, season_numbers, delete_watched,
max_storage_bytes, quality and active. The handler answers 400 for null on
each of them, and docs/downloads-api.md already says null is rejected.

DownloadSubscriptionPatchBody now drops the nullable flag from its members.
Requests are handled as before: Huma treats null on an optional member as
absent, and the handler's check still answers 400.

With quality no longer nullable, the nullable enum exemption has nothing
left to hold out, so NullEnumWithheld and its lint branch go.

This narrows the request contract and needs a breaking-change approval.

* refactor(apiv2): drop the unused schema path from the nullable enum pass

The path only keyed the exemption table, which the previous commit
removed.

* chore(apiv2): approve the monitor patch nullability change

One request-property-became-not-nullable approval per field of
updateDownloadSubscription, ratified in #3535.

* fix(contractspec): check nullable enums wherever the generator adds null

The nullable enum rule walked only members and array items, so a nullable
enum in a oneOf, anyOf or allOf branch or a typed map value passed the lint
although the generator covers those places. The rule now has its own walk
over all of them.

* docs(apiv2): describe the monitor null refusal without its status code

#4064 changes the answer to null on a monitor field from 400 to 422, so
the TransformSchema comment and the approval reasons say the handler
refuses null rather than naming the status.

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

---------

Co-authored-by: Quick104 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@rangoDJ
rangoDJ deleted the fix/subscription-null-422-3720 branch November 15, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/S 0–49 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] v2 monitor edit answers null with 400 instead of 422 validation_failed

2 participants