Repository navigation
fix: answer 400 for a null or missing stay in the booking sample (#465, 10.x) - #469
Merged
Merged
Conversation
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)
Closed
This was referenced Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #465
Cherry-pick (
-x) of #467 intorelease/10.x.Closesdoesn't act on a release branch, so #465 is closed by hand once both PRs merge.Problem
POST /bookingswith{"roomId":1,"guest":"Ada","stay":null}, or with nostay, answered 500 with anUnreachableException. System.Text.Json doesn't check nullable annotations by default, so it boundBookingRequest.Stayasnull, andCheckStayreached its throwing discard arm. An outside pre-tag review ofrelease/10.xfound it. The walkthrough said the discard arm was only there for the compiler.Change
samples/Bookings/BookingApi.cs:CheckStaytakes aDateRange?and answers"Give the stay."fornull, so the sample returns a 400 validation problem.docs/walkthrough.md: quotes the newCheckStay, and a "Good to know" bullet says why a JSONnullreaches the handler (RespectNullableAnnotationsis 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."]}.main(fix: answer 400 for a null or missing stay in the booking sample (#465) #467), where the oldBookingApi.csmakes the test fail withSystem.Diagnostics.UnreachableException. The code is the same here, and the test passes on SDK 10.0.402.WalkthroughSampleConventionTests, which checks that the page quotes the sample verbatim. The sample builds.🤖 Generated with Claude Code