CRM_Core_BAO_Address::addGeocoderData mishandling NULL geocodes
Overview
NULL lat/lng return values from the Nominatim/OSM geocoding service - through either the de.systopia.osm or org.wikimedia.geocoder extensions - are being saved as 0,0. Discussion on Mattermost points to a bug in the CRM_Core_BAO_Address:addGeocoderData
function.
Reproduction steps
- Install, enable and configure either the de.systopia.osm or org.wikimedia.geocoder extensions.
- Load any Contact record
- Add/edit an address; make sure it's one that won't geocode (eg. "123 Alphabet St, Pretendsville")
- You should receive an alert indicating a failure to geocode the address
- Edit the address and inspect the lat/lng fields. They will contain zeroes.
Current behaviour
The latitude and longitude fields (geo_code_1
, geo_code_2
in civicrm_address
) are saving 0
as their values when OSM/Nominatim returns an empty array (ie. no geocode results).
Expected behaviour
The latitude and longitude fields should store NULL
.
Environment information
- CiviCRM: 5.49alpha1/5.46.3
- PHP: 7.3_
- CMS: /Drupal 7.88
- Database: MariaDB 10.4.21
Comments
@seamuslee has highlighted this line in CRM_Core_BAO_Address::addGeocoderData as the most likely cause of the problem.