fix(http-client-python): construct paging JSON body outside prepare_request#10957
Open
l0lawrence wants to merge 1 commit into
Open
fix(http-client-python): construct paging JSON body outside prepare_request#10957l0lawrence wants to merge 1 commit into
l0lawrence wants to merge 1 commit into
Conversation
…equest For paging operations with a flattened JSON model body, the body construction (if body is _Unset: ...) was emitted inside the prepare_request closure. Assigning �ody there made it a function-local, so reading if body is _Unset: raised UnboundLocalError on every page fetch. Move the construction out of the closure and before the body is serialized into the request content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Contributor
|
We don't have spector case for this scenario for now so better to add unit test cases instead @l0lawrence |
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.
Bug
For paging operations whose request body is a flattened JSON model, the generated client raised
UnboundLocalError: cannot access local variable 'body'on the first call. The body construction block was emitted inside theprepare_requestclosure, and sincebodyis assigned there, Python treats it as a function-local for the whole closure, so the earlierif body is _Unset:read fails before it is ever bound.Fix
Construct the JSON model body once in the enclosing method scope (next to where overload body initialization already lives) and before the body is serialized into the request content. The
prepare_requestclosure then only reads the already-built body. This mirrors the existing pattern where_initialize_overloadsreturns early for paging so body setup happens once outside the closure.