From ecf614a54be26990b34c1bf8b5ad0c1a6497f46e Mon Sep 17 00:00:00 2001 From: Terence Tuhinanshu Date: Fri, 19 Jan 2024 15:35:46 -0500 Subject: [PATCH] Tolerate missing Loc_name, warn if on missing keys Previously we assumed that Loc_name would always be provided, given that we ask for it in the requested field list. However, when using the magicKey, the Loc_name is not provided, causing geocoding to fail. By making it optional, we allow those geocoding requests to succeed. Also, add a WARNING to the log when there's a missing key, instead of just silently passing, for better observability. --- omgeo/services/esri.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/omgeo/services/esri.py b/omgeo/services/esri.py index 437bd9d..f6d516c 100644 --- a/omgeo/services/esri.py +++ b/omgeo/services/esri.py @@ -195,7 +195,7 @@ def _geocode(self, pq): c = Candidate() attributes = location['attributes'] c.match_addr = attributes['Match_addr'] - c.locator = attributes['Loc_name'] + c.locator = attributes.get('Loc_name', '') c.locator_type = attributes['Addr_type'] c.score = attributes['Score'] c.x = attributes['DisplayX'] # represents the actual location of the address. @@ -210,7 +210,8 @@ def _geocode(self, pq): setattr(c, out_key, attributes.get(in_key, '')) setattr(c, 'match_streetaddr', self._street_addr_from_response(attributes)) returned_candidates.append(c) - except KeyError: + except KeyError as e: + logger.warning('Missing key: ' + e) pass return returned_candidates