fix: add weather location fallbacks#75
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds fallback mechanisms so the weather flow can still work when precise geolocation (or stored coordinates) aren’t available, by using network-based approximation on the frontend and on-demand geocoding on the backend.
Changes:
- Frontend: introduce shared location helper utilities (+ tests) and update Settings to fall back to IP-based approximate coordinates when browser geolocation fails.
- Backend: add
WeatherService.geocode_location_name()and update weather endpoints to geocodelocation_namewhen coordinates are missing (plus API tests). - UX: improve user-facing messaging when exact geolocation fails and approximate data is used.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/tests/location.test.ts | Adds unit coverage for new location helper utilities. |
| frontend/lib/location.ts | Introduces helpers for resolving network location responses, reverse-geocode formatting, and geolocation error messaging. |
| frontend/app/dashboard/settings/page.tsx | Adds network-location fallback and refactors reverse geocoding + messaging in Settings. |
| backend/tests/test_weather_api.py | Adds API-level tests for geocoding fallback behavior and missing-location errors. |
| backend/app/services/weather_service.py | Adds a Nominatim geocoding helper for resolving location_name to coordinates. |
| backend/app/api/weather.py | Uses geocoding fallback in /weather/current and /weather/forecast when coordinates aren’t stored/provided. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
Validation update for latest branch push:
Note: |
This was referenced May 13, 2026
This comment was marked as outdated.
This comment was marked as outdated.
Cache Nominatim geocode results in Redis (30-day TTL) so a saved location name is geocoded at most once per TTL instead of on every weather request, avoiding Nominatim rate-limit bans and keeping the external call off the weather hot path.
Gate the IP-based location fallback behind NEXT_PUBLIC_ENABLE_IP_LOCATION_FALLBACK (off by default) so the user's IP is only sent to a third party when an operator explicitly enables it. Document the flag and provider override in README and .env.example.
Owner
|
Thankyou for your PR 🙏🏽 |
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
location_nameon the backend when weather endpoints are called without stored coordinatesTesting
npm test -- --run tests/location.test.tsnpx tsc --noEmitdocker compose exec -T -e TEST_DATABASE_URL=postgresql+asyncpg://wardrobe:4f5a5cb732900d2d7890d3bcb215f05268b2dce7e6188c2d56810cd8e9ccba91@postgres:5432/wardrobe_test backend pytest tests/test_weather_api.pyNotes
.gitignorehas local changes in the worktree and is intentionally excluded from this PR.