From 889dd790eafc961f06cd6adbb3d6cf74ab0f400a Mon Sep 17 00:00:00 2001 From: justin-outdoorithm Date: Sun, 4 Jan 2026 13:48:51 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20GoingToCamp=20KeyError=20w?= =?UTF-8?q?hen=20listing=20campgrounds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CAMP_DETAILS API returns regional map data where all entries have resourceLocationId=None, causing the campground_details dictionary to only contain {None: }. When _process_facilities_responses tries to look up the actual facility's resource_location_id, it raises a KeyError. This fix uses the rootMapId field that's already present in the LIST_CAMPGROUNDS API response instead of the broken CAMP_DETAILS lookup. Changes: - Add root_map_id field to ResourceLocation class - Capture rootMapId from LIST_CAMPGROUNDS in _filter_facilities_responses - Use facility.root_map_id directly in _process_facilities_responses - Remove unused CAMP_DETAILS API call and campground_details dictionary Fixes #377 --- camply/containers/gtc_api_responses.py | 1 + .../providers/going_to_camp/going_to_camp_provider.py | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/camply/containers/gtc_api_responses.py b/camply/containers/gtc_api_responses.py index 0ba0d33f..992dbacd 100644 --- a/camply/containers/gtc_api_responses.py +++ b/camply/containers/gtc_api_responses.py @@ -18,3 +18,4 @@ class ResourceLocation(CamplyModel): resource_location_id: Optional[int] resource_location_name: str region_name: str + root_map_id: Optional[int] = None diff --git a/camply/providers/going_to_camp/going_to_camp_provider.py b/camply/providers/going_to_camp/going_to_camp_provider.py index 506a70ff..09fddeff 100644 --- a/camply/providers/going_to_camp/going_to_camp_provider.py +++ b/camply/providers/going_to_camp/going_to_camp_provider.py @@ -275,7 +275,6 @@ def find_facilities_per_recreation_area( logger.error(f"Recreation area '{rec_area_id}' does not exist.") sys.exit(1) - self.campground_details = {} api_response = self._api_request(rec_area_id, "LIST_CAMPGROUNDS") filtered_facilities = self._filter_facilities_responses( @@ -283,9 +282,6 @@ def find_facilities_per_recreation_area( ) campgrounds = [] - # Fetch campgrounds details for all facilities - for camp_details in self._api_request(rec_area_id, "CAMP_DETAILS"): - self.campground_details[camp_details["resourceLocationId"]] = camp_details # If a search string is provided, make sure every facility name contains # the search string @@ -387,6 +383,7 @@ def _filter_facilities_responses( resource_categories=facil.get("resourceCategoryIds"), resource_location_id=facil.get("resourceLocationId"), resource_location_name=location_name, + root_map_id=facil.get("rootMapId"), ) except ValidationError as ve: logger.error("That doesn't look like a valid Campground Facility") @@ -424,10 +421,7 @@ def _process_facilities_responses( ------- Tuple[dict, CampgroundFacility] """ - self.campground_details[facility.resource_location_id] - facility.id = _fetch_nested_key( - self.campground_details, facility.resource_location_id, "mapId" - ) + facility.id = facility.root_map_id if facility.region_name: formatted_recreation_area = ( f"{rec_area.recreation_area}, {facility.region_name}"