Repository navigation
Cache statsbombpy's requests in its own session instead of patching requests globally - #90
Merged
Merged
Conversation
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| Secrets | View in Orca |
willnewton
approved these changes
Oct 19, 2026
willnewton
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the contribution!
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.
Fixes #85
api_client.py called requests_cache.install_cache() at import time, which patches requests for the whole process. Importing statsbombpy therefore changed caching for every requests call in the host application.
This follows the fix suggested in the issue: a requests_cache.CachedSession that only statsbombpy uses.
Change
New statsbombpy/cache.py with one CachedSession (same sqlite backend in a temp directory, same CACHED_CALLS_SECS expiry as before).
api_client.get_resource() and public.get_response() use that session. The open-data client was relying on the global patch for its caching, so it keeps its cache this way.
Two tests: importing statsbombpy leaves requests untouched (requests_cache.is_installed() is False), and both clients go through the statsbombpy session.
Checked
Both new tests fail on master and pass with the change.
The rest of the suite: 9 tests need StatsBomb API credentials, which I do not have, and fail the same way before and after the change ("please provide credentials"). All other tests pass.
AI-assisted: I used an AI assistant to make the change and write the tests; I reviewed it and ran the tests before and after.