fix(functions): copy headers in invoke() to avoid leaking them across calls#1536
Open
winklemad wants to merge 1 commit into
Open
fix(functions): copy headers in invoke() to avoid leaking them across calls#1536winklemad wants to merge 1 commit into
winklemad wants to merge 1 commit into
Conversation
… calls `invoke()` assigned `headers = self.headers` and then mutated it with the call's `headers` option and the body `Content-Type`, writing those back onto the client's persistent headers. Every later `invoke()` then inherited them. Copy `self.headers` instead, matching functions-js (which builds a fresh header object per call) and the header-mutation fix in supabase#1249, which corrected the constructor but left this path untouched.
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.
No linked issue — found by reading the functions client.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
AsyncFunctionsClient.invoke()(and its sync twin) aliases the client's persistent header dict instead of copying it:So every call's one-off
headersoption, itsx-region, and the bodyContent-Typeare written back ontoself.headersand leak into all laterinvoke()calls:What is the new behavior?
invoke()copies the client headers (headers = {**self.headers}) before mutating them, so per-call headers stay per-call andself.headersis never modified. This matches functions-js, which builds a fresh header object per request, and completes the header-mutation fix from #1249 (which corrected the constructor but left thisinvoke()path aliasingself.headers).Additional context
Fixed in both
_asyncand_syncclients. Addedtest_invoke_does_not_leak_headers_between_callsto the async and sync test suites — it fails on the current code (self.headersgainsContent-Typeand the per-call header) and passes with the fix. Full functions test suite passes;ruffcheck + format are clean.