Repository navigation
build!: require FOCA 0.17 and Python 3.13 - #245
Conversation
ip2geotools (last release 2021) is unmaintained and requires typed-ast, which doesn't build on Python 3.13. The distance-based middleware now calls the services that ip2geotools used directly: DB-IP's free API for the place of an IP address (over HTTPS instead of HTTP), and Nominatim, via geopy (already a dependency), for its coordinates, with the same fallback query without the region. Requests time out after 10 seconds (was 62), and each IP address is located once per task. requests is declared, as proTES uses it directly. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
proTES targets one Python version, that of the base image: 3.13. CI runs one mongomock test job (no Python version in its name) besides the MongoDB job, with the aggregate check "Run tests"; linting, docs and Read the Docs use 3.13, too. tests/test_build.py checks that the versions match. Until FOCA 0.17.0 is released, proTES is built and tested against a FOCA dev commit, with FOCA's dev image of that commit as base image, pinned by digest (as in cloud-registry): scripts/image_requirements.py leaves the pin out of the image's requirements and fails unless the base image has that commit; scripts/check_release_pins.py, run by the tests for release checkouts, fails while dev pins are left. Dependabot ignores the base image meanwhile. The build stage that compiled typed-ast is no longer needed. BREAKING CHANGE: Python 3.10 to 3.12 are no longer supported. With FOCA 0.16 and 0.17, only access tokens (typ header at+jwt) are accepted, and configured policy rules are replaced atomically on startup (removed if no rules are configured); see docs/upgrading.md. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.16 adds the WWW-Authenticate challenge to 401 responses, so the after_request function that proTES added for FOCA 0.15 is removed. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The base config sets verify_token_type explicitly and documents the new clients allowlist (no default); the docs describe both, and the tests check that ID tokens and tokens of clients that aren't listed are rejected with 401. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.17's named entries let overlays change, add or remove single specs or policy rules by name, instead of restating the lists. Lists in overlays still replace them. Closes #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses that are not global (e.g., private ones of hosts in the same cluster) are no longer sent to the geolocation services, and places without city or country (DB-IP's answer for reserved addresses) are not geocoded: Nominatim matched such near-empty queries to arbitrary places, by which tasks were distributed. The middleware falls back to the next one for them. Each address is located once per task. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
proTES has no release workflow yet (#44), and the tests skip the pin check in CI, whose checkouts have no tags. A workflow for pushed release tags runs scripts/check_release_pins.py, so that a tag with development pins fails before its GitHub release is published. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR upgrades proTES to FOCA 0.17 and Python 3.13 using a digest-pinned FOCA development image, adds automated safeguards for build/release pin consistency, replaces the incompatible geolocation dependency with direct DB-IP/Nominatim integration, and adopts FOCA's authentication and named-configuration features. Sequence diagram for IP geolocation during distance-based task distributionsequenceDiagram
participant Middleware
participant DBIP
participant Nominatim
Middleware->>Middleware: ip_address_info(ip_address)
alt address is not global
Middleware-->>Middleware: MiddlewareException
else address is global
Middleware->>DBIP: requests.get(DB_IP_URL, timeout=TIMEOUT)
DBIP-->>Middleware: city, region, country
alt city or country unavailable
Middleware-->>Middleware: MiddlewareException
else place is available
Middleware->>Nominatim: geocode(query)
alt region query not found
Middleware->>Nominatim: geocode(city, country)
end
Nominatim-->>Middleware: latitude, longitude
Middleware-->>Middleware: Location
end
end
Flow diagram for release pin safeguardsflowchart TD
Tag[Push v* tag] --> Workflow[release-pins.yaml]
Workflow --> Check[check_release_pins.py]
Check --> Dependencies[Check project dependencies]
Check --> Base[Check FOCA base image tag]
Check --> Chart[Check Helm chart versions]
Dependencies --> Result{All are releases?}
Base --> Result
Chart --> Result
Result -->|yes| Publish[Release may be published]
Result -->|no| Fail[Fail with release-pin errors]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #245 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 20 22 +2
Lines 987 1097 +110
==========================================
+ Hits 987 1097 +110 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_tes/plugins/middlewares/task_distribution/distance.py" line_range="93" />
<code_context>
+ if region:
+ queries.insert(0, f"{city}, {region} {country}")
+ geocoder = Nominatim(user_agent=USER_AGENT, timeout=TIMEOUT)
+ for query in queries:
+ try:
+ point = geocoder.geocode(query)
</code_context>
<issue_to_address>
**Distance routing falls back**
When multiple addresses or concurrent and repeated tasks generate geocoding requests, `locate_ip` sends each query immediately, while `_get_ip_locations` deduplicates only within one task. Nominatim rejects over-limit calls, and repeated lookups consume DB-IP’s daily allowance; the resulting errors raise `MiddlewareException` and send placement to random routing.
Apply an application-wide rate limit and reuse IP-location results across tasks to stay within Nominatim’s one-request-per-second limit and avoid exhausting DB-IP’s daily allowance.
Also at `pro_tes/plugins/middlewares/task_distribution/distance.py:95`, `pro_tes/plugins/middlewares/task_distribution/distance.py:313`.
</issue_to_address>
### Comment 2
<location path="scripts/check_release_pins.py" line_range="108" />
<code_context>
+ pins.append(
+ f"pyproject.toml: dependency '{requirement}' is a direct reference"
+ )
+ elif PRE_RELEASE.search(re.sub(NAME, "", requirement).split(";")[0]):
+ pins.append(
+ f"pyproject.toml: dependency '{requirement}' names a pre-release"
</code_context>
<issue_to_address>
**Custom builds pass the release check**
When a dependency is pinned to a PEP 440 local version such as `==1.2.3+gabc`, `PRE_RELEASE` does not recognize local version labels, so `find_dev_pins` accepts the requirement and a release can include a dependency build that is not a released version.
Recognize and reject PEP 440 local version labels in the release-pin check.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and the FOCA upgrade changes token validation and how named access-control rules are applied and persisted at startup. If those rules admit unintended requests, reverting will not undo data accessed while the change was live; the new geolocation flow also sends derived place information to Nominatim.
Blocking findings: pro_tes/plugins/middlewares/task_distribution/distance.py:93, scripts/check_release_pins.py:108
PEP 440 local versions (e.g., ==0.17.0+gabc1234) are builds, not releases, so the release pin check reports them, too (Sourcery). Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
proTES now targets FOCA 0.17 and one Python version, 3.13 (the base image's). FOCA 0.17.0 isn't on PyPI yet, so this PR builds and tests against a pinned FOCA
devcommit, as cloud-registry did in elixir-cloud-aai/cloud-registry#184. A follow-up switches to the release.pyproject.tomlpinsfoca @ git+https://github.com/elixir-cloud-aai/foca@29af8a64a2b0aae21845fa37a4a54076811f62bf(FOCAdev, including the 0.17.0 pre-release fixes), marked TEMPORARY.The
DockerfilebuildsFROM elixircloud/foca:20261023-py3.13@sha256:1e1275f7…, FOCA's development image of that commit (FOCA0.16.1.dev16+g29af8a64a). The comment## FOCA commit: <sha>records the commit.scripts/image_requirements.py(ported from cloud-registry) leaves the Git pin out of the image's requirements, because the image has no Git. It fails the build unless the base image's FOCA is that commit.scripts/check_release_pins.py(ported) fails while any of these is left: a direct reference, a pre-release dependency, a non-release base image tag or a non-release chart dependency. proTES has no release workflow yet (ci: release from signed version tags #44, PR ci!: release from signed version tags #230 is still a draft), so the check runs in two places:release-pins.yaml, on every pushedv*tag, before the GitHub release is published (Zenodo archives at that point);tests/test_check_release_pins.py::test_release_checkout, for checkouts of release tags.ci: release from signed version tags #44 has a comment saying that the release workflow must run the check.
Dependabot ignores the base image for now.
tests/test_build.pychecks two things: the base image matches thefocapin (release or commit), and the Python version is the same everywhere.requires-python = ">=3.13", with only 3.13 in the classifiers. ruff and mypy target 3.13.tomliand the 3.10 code paths are gone, and ruff'sUP017fixes are applied.Run tests (mongomock)job (no matrix, no Python version in the name) andRun tests (MongoDB 7.0), with the aggregate required checkRun tests, as in cloud-registry. Linting and docs run on 3.13, and so does Read the Docs.typed-astis gone. The image is single-stage again, as in cloud-registry.typed-ast, which doesn't build on 3.13.DbIpCity.get()called DB-IP's free API for the city, region and country, then OpenStreetMap's Nominatim, through the unmaintainedgeocoderpackage, for the coordinates.locate_ip()indistance.py), with the same queries and the same fallback without the region:requestsis now declared, because proTES uses it directly. The timeout is 10 s (it was 62 s), and each IP address is looked up once per task. Every failure raisesMiddlewareException, so the random middleware takes over as before.ZZ) are no longer geocoded. Before, Nominatim matched such queries to an arbitrary place, as it already did with ip2geotools.WWW-Authenticateshim from feat(auth)!: require tokens for task operations #212 is removed: FOCA ≥ 0.16 sends the Bearer challenge itself (with anerror_description).api.specs(tes) andsecurity.access_control.policies(users-create-list-tasks,users-get-cancel-tasks) are named entries. Overlays can change single rules or specs by name, and overlays that give lists still replace them.verify_token_type: Trueexplicitly and documents theclientsallowlist with a generic placeholder (no default).typ: JWT) get401; withclients, tokens of other clients or without a client get401, whileclient_idandazpmatches pass; a named-policy overlay removes one rule.Out of scope, as decided: TES 1.1 (#241), service tokens (#213), task ownership (#215), chart (#216), middlewares (#217).
Closes #214
How it was verified
coverage run -m pytest(Python 3.13.15, FOCA0.16.1.dev16+g29af8a64a): 305 passed, 1 skipped (test_release_checkout, not a release checkout);coverage report100%.MONGODB_TEST_URI=… pytestagainstmongo:7.0: 294 passed, 1 skipped.pre-commit run --all-filesand--hook-stage manual gitleaks-all: passed.mkdocs build --strict: passed.docker-compose.yaml:tests/smoke/compose.yaml,up --build --wait,tests/smoke/check.sh): passed. The image runs Python 3.13.17 and FOCA0.16.1.dev16+g29af8a64a, and has neither ip2geotools nor typed-ast.locate_ip()worked against the live services: 8.8.8.8 gave Mountain View and 193.166.3.2 gave Espoo.Sourcery review
Sourcery opened 2 threads. Both are answered and resolved:
==0.17.0+gabc1234).Declined review findings
release-pins.yamlonly reports and can't block publishing a release from the tag (adversarial and quality, round 2, low). Accepted until the release workflow of ci: release from signed version tags #44 runs the check before publishing;docs/development.mdsays to check the result first, and ci: release from signed version tags #44 has a comment about it.test_rank_same_addressdoesn't test ordering (quality, round 2, low). Intended: it tests deduplication; the order of lookups depends onset()upstream anyway.USER_AGENT).Open questions
None.
Follow-up once FOCA 0.17.0 is released
pyproject.toml:foca>=0.17.0,<0.18instead of the Git pin; remove the TEMPORARY comment.Dockerfile:FROM elixircloud/foca:0.17.0-py3.13@sha256:<digest>; remove the## FOCA commitline and the TEMPORARY comment..github/dependabot.yml: remove the temporaryelixircloud/focaignore, keeping the minor/major one.docs/upgrading.mdstays as it is. The release guard keeps failing on release checkouts until then.🤖 Generated with Claude Code