Skip to content

fix: answer 400 for a null or missing stay in the booking sample (#465, 10.x) - #469

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/465-sample-null-stay-10x
Oct 25, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/465-sample-null-stay-10x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #465

Cherry-pick (-x) of #467 into release/10.x. Closes doesn't act on a release branch, so #465 is closed by hand once both PRs merge.

Problem

POST /bookings with {"roomId":1,"guest":"Ada","stay":null}, or with no stay, answered 500 with an UnreachableException. System.Text.Json doesn't check nullable annotations by default, so it bound BookingRequest.Stay as null, and CheckStay reached its throwing discard arm. An outside pre-tag review of release/10.x found it. The walkthrough said the discard arm was only there for the compiler.

Change

  • samples/Bookings/BookingApi.cs: CheckStay takes a DateRange? and answers "Give the stay." for null, so the sample returns a 400 validation problem.
  • docs/walkthrough.md: quotes the new CheckStay, and a "Good to know" bullet says why a JSON null reaches the handler (RespectNullableAnnotations is off by default).

The sample isn't in a package, so there is no changelog row.

Tests

  • WalkthroughSampleTests (live): posts a null stay and a body with no stay, and expects the 400 with {"stay":["Give the stay."]}.
  • Reverted on main (fix: answer 400 for a null or missing stay in the booking sample (#465) #467), where the old BookingApi.cs makes the test fail with System.Diagnostics.UnreachableException. The code is the same here, and the test passes on SDK 10.0.402.
  • Conventions pass, including WalkthroughSampleConventionTests, which checks that the page quotes the sample verbatim. The sample builds.

🤖 Generated with Claude Code

System.Text.Json doesn't check nullable annotations by default, so "stay":null, or a body
with no stay, bound BookingRequest.Stay as null. CheckStay then reached its throwing
discard arm and the sample answered 500 with an UnreachableException. CheckStay now takes
a DateRange? and answers "Give the stay." for null, and the walkthrough quotes the new
code and says why null arrives.

Found-By: RV
Defect-Class: JSON

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a32d2a5)
@CaffeinatedCoder CaffeinatedCoder added this to the 10.3.0 milestone Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference labels Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder mentioned this pull request Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 7c01380 into release/10.x Oct 25, 2026
10 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/465-sample-null-stay-10x branch October 25, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant