-
Notifications
You must be signed in to change notification settings - Fork 184
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
Fix: ensure custom session can be provided to rest client #1396
Conversation
✅ Deploy Preview for dlt-hub-docs canceled.
|
This is also confusing dlt/dlt/sources/helpers/rest_client/client.py Lines 186 to 190 in 64c9538
Why is this there is raise for status is intended to be configured at session level EDIT: Its nice being able to configure these though. Just confusing contrasted with the requests Client which may be the source of my confusion. |
Also note, you bypass dlt/dlt/sources/helpers/rest_client/client.py Lines 92 to 133 in 64c9538
And call dlt/dlt/sources/helpers/requests/retry.py Line 242 in 64c9538
I can fix that too. It will specifically fix passing in the dlt requests Cient into RESTClient and benefitting from the retry logic. |
262008e
to
e2e1e32
Compare
b46e8a6
to
6923202
Compare
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.
Thanks for spotting this and for the fix! I have a couple of comments to the PR below.
Yes, very good catch! Thanks for the fix again.
Agreed, not the most elegant solution, the idea is to enable hooks while having the rase_for_status as a default. This is also related to the session check. I wanted to give the user a way to override the default behaviour. Naturally the suggestions of how to do this better are very welcome! |
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.
LGTM!
one question: are you trying to use a session that is not from requests
library? ie httpx
?
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.
I think that your change somehow broke one test where I expect the host is mocked.
FAILED tests/sources/helpers/rest_client/test_client.py::TestRESTClient::test_oauth_jwt_auth_success - requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /oauth/token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f08d16f1710>: Failed to establish a new connection: [Errno -2] Name or service not known'))
@z3z1ma pls ping us if you have time to investigate that soon, otherwise we'll take over
Test is passing for me 🤔 interesting, it shouldnt be flaky? Also was doing my PR reply using https://github.com/pwntester/octo.nvim and totally replied via appending/editing your comments by accident (didnt even know that was possible) |
Actually I was trying to use the dlt requests Client.session (I had done some custom stuff but wanted the default retry logic).
Would it make more sense to inherit from the session by default? This way the behavior is consistent within a source but can still be overridden on a per endpoint basis? I need to double check if/how sessions exposes this. |
Yeah I was also contemplating this. But in that case how do we allow the user to pass their own Session? |
I've checked out the branch locally and also don't see this test_oauth_jwt_auth_success error. 🤔 |
this is due to the OAuthAuth using default dlt session which is created before the mock by some other test... let me take a look and fix it |
Interesting |
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.
Looks good, @z3z1ma! Thanks for fixing it!
Description
A simple fix for a small oversight in the rest client. Additionally a test proving you can pass a custom session and there is no crash.
Related Issues
Additional Context