-
Notifications
You must be signed in to change notification settings - Fork 8
SyncClient: update session with transport's headers #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shtrom
wants to merge
3
commits into
mozilla-releng:main
Choose a base branch
from
shtrom:issue202/rest-client-headers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+51
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got 2 issues.
It's not in the right place. It should be in
_get_gql_sessionor doingGQL->REST->GQLwith the same object ends up with the second gql call behaving different.And secondly, this overrides all headers instead of updating them. So we lose default headers (notably
Accept-EncodingandUser-Agent).Something like this test shows both well:
You get:
I'm 95% sure the UA missing gets saved by urllib3 later on and that it'll work anyway (github requires a UA) but it's a very weird behavior and I don't want to have to debug something 6 months from now because the UA changes depending on request order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, a dict update would be better.
I started moving this, but I have misgivings:
_get_requests_sessionis the method that specifically reaches deep into thesessionto get thetransport.session, which happens to not be exactly as we'd expect (which is not contractually guaranteed by gql graphql-python/gql#613 (comment)). I think it makes more sense to be fixing the session in_get_requests_sessionrather than in_get_gql_session(note that they are note the same “session”), though perhaps it's not desirable to morph it for everything, and instead we should copy it before updating the headers.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I just found this part of a test https://github.com/shtrom/simple-github/blob/9f64417ca1f20aed1861cc58083652a07cf96ef4/test/test_client.py#L117-L120 that seems to have the same intent as the ones I added... but it doesn't check the headers of the returned
session, and instead check thetransport(that I suggest we update from).Perhaps this test can be updated instead to test the session?
OTOH, I found this test when I started
deepcopying thesession, which broke the equality assertions here.I'm not sure what the best approach would be here:
deepcopy.In favour of 1, I'm not even sure we can
deepcopytherequests.Sessionsafely.WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, if we
updatewithout adeepcopy, we might as well do it ASAP, so in_get_gql_sessionas you suggest. But we're essentially fiddling withgql's (semi) internals.