Skip to content

fix: use RateLimiter in geocode_object to respect Nominatim 1 req/s p…#27

Merged
remdub merged 3 commits intomainfrom
WEB-4423
May 5, 2026
Merged

fix: use RateLimiter in geocode_object to respect Nominatim 1 req/s p…#27
remdub merged 3 commits intomainfrom
WEB-4423

Conversation

@remdub
Copy link
Copy Markdown
Member

@remdub remdub commented May 5, 2026

…olicy and catch GeocoderRateLimited so bulk imports are not aborted on 429

WEB-4423

Summary by CodeRabbit

  • Bug Fixes

    • Bulk geocoding now catches rate-limit and service-unavailable errors, allowing imports to continue instead of aborting on API limits.
  • Tests

    • Added test covering rate-limit handling; updated geocoding tests to mock internal behavior and assert graceful failure when services are unavailable or rate limited.
  • Documentation

    • Changelog updated with the new geocoding/rate-limit entry.

…olicy and catch GeocoderRateLimited so bulk imports are not aborted on 429

WEB-4423
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0163b09a-d9ea-4533-8133-23d9e81c37e2

📥 Commits

Reviewing files that changed from the base of the PR and between 76dbaff and f378a89.

📒 Files selected for processing (1)
  • src/imio/smartweb/common/utils.py
✅ Files skipped from review due to trivial changes (1)
  • src/imio/smartweb/common/utils.py

📝 Walkthrough

Walkthrough

Geocoding now uses a module-level Nominatim geolocator wrapped by a RateLimiter (~1 req/s); geocode_object calls this rate-limited helper and catches GeocoderRateLimited in addition to GeocoderUnavailable, returning False on those errors to avoid aborting bulk imports.

Changes

Rate-Limited Geocoding

Layer / File(s) Summary
Rate-limited helper
src/imio/smartweb/common/utils.py
Adds module-level _geolocator = Nominatim(...) and _geocode = RateLimiter(_geolocator.geocode, min_delay_seconds=1) to centralize and throttle geocoding calls.
Core usage
src/imio/smartweb/common/utils.py
geocode_object now calls _geocode(address) instead of creating a local geolocator per call.
Error handling
src/imio/smartweb/common/utils.py
Expanded except block to catch geopy.exc.GeocoderRateLimited alongside GeocoderUnavailable; warning message updated and the function returns False on these errors.
Tests
src/imio/smartweb/common/tests/test_utils.py
Tests updated to patch imio.smartweb.common.utils._geocode; existing tests adapt and a new test_geocode_object_geocoder_rate_limited asserts geocode_object returns False when _geocode raises GeocoderRateLimited.
Changelog
CHANGES.rst
Adds 1.2.53 (unreleased) entry (WEB-4423) documenting RateLimiter usage and handling of rate-limited responses during bulk imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped along the mapping trail,
One gentle pause — a paced-out tale,
Each geocode now a careful beat,
Bulk hops pass by without defeat,
🌿📍

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing RateLimiter to geocode_object to respect Nominatim's rate limits, which aligns with the core objective of the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch WEB-4423

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/imio/smartweb/common/utils.py`:
- Around line 83-90: Move the geopy RateLimiter and Geolocator out of the
per-call scope into module scope so the same RateLimiter instance is reused
(e.g., create geolocator = geopy.geocoders.Nominatim(...) and geocode =
RateLimiter(geolocator.geocode, min_delay_seconds=1, swallow_exceptions=False)
at module top), and update geocode_object to call that module-level geocode;
setting swallow_exceptions=False ensures real exceptions propagate so the
existing except (geopy.exc.GeocoderUnavailable, geopy.exc.GeocoderRateLimited)
in geocode_object can actually catch them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f3c187a-4c76-45ca-bd6b-61b7df5756cf

📥 Commits

Reviewing files that changed from the base of the PR and between 46ed6ca and 89aeb70.

📒 Files selected for processing (3)
  • CHANGES.rst
  • src/imio/smartweb/common/tests/test_utils.py
  • src/imio/smartweb/common/utils.py

Comment thread src/imio/smartweb/common/utils.py Outdated
@remdub remdub merged commit 4d1dc58 into main May 5, 2026
9 checks passed
@remdub remdub deleted the WEB-4423 branch May 5, 2026 08:08
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.

1 participant