Skip to content

Surface ipinfo.io location check failures (closes #1311)#1312

Open
kunal-10-cloud wants to merge 1 commit intomalariagen:masterfrom
kunal-10-cloud:fix/issue-1311-ipinfo-silent-error
Open

Surface ipinfo.io location check failures (closes #1311)#1312
kunal-10-cloud wants to merge 1 commit intomalariagen:masterfrom
kunal-10-cloud:fix/issue-1311-ipinfo-silent-error

Conversation

@kunal-10-cloud
Copy link
Copy Markdown
Contributor

Summary

Closes #1311.

The ipinfo.io lookup performed in AnophelesBase.__init__ swallowed every OSError silently, leaving _client_details = None. That cascaded into _get_gcp_region() returning None, 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

  • Performance: Researchers near a GCS region (e.g. us-central1) could unknowingly pull multi-GB datasets from a distant bucket.
  • Debuggability: Slow-download reports had nothing in the application state or logs to correlate with a failed ipinfo.io lookup.
  • Prevalence: The networks most likely to block external lookups (corporate firewalls, institutional VPNs, restricted regions) are exactly the environments where many researchers operate.

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 with debug=True.
  • warnings.warn(..., UserWarning, stacklevel=2) surfaces the failure to end users with an actionable hint about the url override, without being intrusive in the common success path.
  • warnings is already imported at the top of the module; self._log is 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 passed
  • CI matrix on PR (linting, coverage, tests across Python 3.10/3.11/3.12 × numpy 2.0.2 / >=2.0.2,<2.1)

Backwards compatibility

No public API changes. No change to fallback behaviour. The only observable difference is a UserWarning (and a DEBUG log entry when debug=True) when the ipinfo.io lookup fails, which previously produced no signal at all.

Copilot AI review requested due to automatic review settings April 18, 2026 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.io lookup raises OSError.
  • Emit a UserWarning with 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.
@kunal-10-cloud kunal-10-cloud force-pushed the fix/issue-1311-ipinfo-silent-error branch from 82f8d35 to dbc4f46 Compare April 18, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipinfo Location Check Silently Swallows All Network Errors With No Logging or Fallback Notification

2 participants