Allow a custom requests.Session for provider-list scraping#2380
Open
vasa-develop wants to merge 2 commits into
Open
Allow a custom requests.Session for provider-list scraping#2380vasa-develop wants to merge 2 commits into
vasa-develop wants to merge 2 commits into
Conversation
get_providers, get_child_database_links and get_all_databases now accept an optional `session` argument so custom HTTP configuration (e.g. proxies) can be used when scraping the provider list. The default behaviour is unchanged (module-level `requests`).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2380 +/- ##
==========================================
- Coverage 90.58% 90.56% -0.02%
==========================================
Files 75 75
Lines 5034 5035 +1
==========================================
Hits 4560 4560
- Misses 474 475 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The SSL-error retry path in get_child_database_links (verify=False) was the one line of the session change left uncovered. Add a regression test that raises SSLError on the first call and asserts the skip_ssl retry also goes through the provided session with verify disabled.
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 #2275.
Problem
get_all_databases()and its helpers (get_providers(),get_child_database_links()) inoptimade/utils.pycall the module-levelrequests.get(...)directly, so there is no way to supply custom HTTP configuration (e.g. a proxy) when scraping the provider list. As reported in #2274, this makes it impossible to use the client behind a proxy without manually specifying base URLs.Fix
Add an optional
session: requests.Session | None = Noneargument to the three scraping functions. When supplied, the request is routed throughsession.get(...); otherwise the behaviour is unchanged (module-levelrequests, which is what the reference server relies on at initialisation, as noted in the issue).get_all_databasesthreads the session down to both helpers.This is intentionally scoped to the
optimade.utilsscrapers, matching the issue's suggestion to "refactorget_all_databases(and related functions) to use a custom HTTP client/session, but ... default to doing their own thing". Wiring this intoOptimadeClientitself can follow separately if desired — happy to do that in a follow-up.Example:
Test plan
tests/server/routers/test_utils.py:test_get_providers_uses_provided_session— a supplied session is used and the globalrequests.getis not.test_get_child_database_links_uses_provided_session— same for the child-link request.test_get_all_databases_threads_session— the session is forwarded to both helpers.main(TypeError: unexpected keyword argument 'session') and pass with this change.test_utils.pytests still pass;ruff check,ruff format --check, andmypyare clean.Thanks to @hongyi-zhao for the original report in #2274.