Skip to content

Commit

Permalink
Tolerate missing Loc_name, warn if on missing keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rajadain committed Jan 19, 2024
1 parent 2a134fb commit ecf614a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions omgeo/services/esri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit ecf614a

Please sign in to comment.