Surface ipinfo.io location check failures (closes #1311)#1312
Open
kunal-10-cloud wants to merge 1 commit intomalariagen:masterfrom
Open
Surface ipinfo.io location check failures (closes #1311)#1312kunal-10-cloud wants to merge 1 commit intomalariagen:masterfrom
kunal-10-cloud wants to merge 1 commit intomalariagen:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes failures in the ipinfo.io-based client geolocation check visible to users, so region-optimal GCS bucket selection doesn’t silently degrade when the lookup fails (closes #1311).
Changes:
- Add DEBUG logging when the
ipinfo.iolookup raisesOSError. - Emit a
UserWarningwith actionable guidance when the location lookup fails, while keeping the existing fallback behavior unchanged.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+111
to
+112
| "unavailable. You can manually specify a region using " | ||
| "the `url` parameter.", |
Comment on lines
+106
to
+110
| except OSError as exc: | ||
| self._log.debug(f"Location check failed: {exc}") | ||
| warnings.warn( | ||
| "Could not determine client location via ipinfo.io " | ||
| f"({exc}). Region-optimal GCS bucket selection is " |
Closes malariagen#1311. The ipinfo.io lookup in AnophelesBase swallowed every OSError silently, leaving _client_details = None. That cascaded into _get_gcp_region() returning None and the GCS URL optimisation falling back to the default bucket without any indication that the location check had failed. Researchers on restricted networks (corporate firewalls, institutional VPNs, regions where ipinfo.io is blocked) hit this path the most, and had no way to correlate slow downloads with a failed lookup. Now the failure is logged at DEBUG level for users running with debug=True, and a UserWarning is emitted explaining the fallback and pointing to the `url` parameter as a manual override. The fallback behaviour itself is unchanged.
82f8d35 to
dbc4f46
Compare
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.
Summary
Closes #1311.
The
ipinfo.iolookup performed inAnophelesBase.__init__swallowed everyOSErrorsilently, leaving_client_details = None. That cascaded into_get_gcp_region()returningNone, which in turn caused the GCS URL optimisation (selecting a region-local bucket) to fall back to the default bucket — without any indication that the location check had failed.The failure mode was indistinguishable from a successful lookup that returned no location data, which is exactly the situation #1311 describes.
Why it matters
us-central1) could unknowingly pull multi-GB datasets from a distant bucket.ipinfo.iolookup.Change
malariagen_data/anoph/base.py, lines 100–105.Before:
```python
self._client_details = None
if check_location:
try:
self._client_details = ipinfo.getHandler().getDetails()
except OSError:
pass
```
After:
```python
self._client_details = None
if check_location:
try:
self._client_details = ipinfo.getHandler().getDetails()
except OSError as exc:
self._log.debug(f"Location check failed: {exc}")
warnings.warn(
"Could not determine client location via ipinfo.io "
f"({exc}). Region-optimal GCS bucket selection is "
"unavailable. You can manually specify a region using "
"the `url` parameter.",
UserWarning,
stacklevel=2,
)
```
The fallback behaviour itself is unchanged; the fix is purely additive.
self._log.debug(...)captures the underlying exception for users running withdebug=True.warnings.warn(..., UserWarning, stacklevel=2)surfaces the failure to end users with an actionable hint about theurloverride, without being intrusive in the common success path.warningsis already imported at the top of the module;self._logis initialised on the line immediately preceding this block, so the warning is safe to emit in__init__.Test plan
pre-commit run --files malariagen_data/anoph/base.py— passed (ruff, ruff-format, trailing-whitespace, end-of-file)poetry run mypy malariagen_data/anoph/base.py— passed (no issues)poetry run pytest tests/anoph/test_base.py— 44 passedBackwards compatibility
No public API changes. No change to fallback behaviour. The only observable difference is a
UserWarning(and a DEBUG log entry whendebug=True) when theipinfo.iolookup fails, which previously produced no signal at all.