diff --git a/addons/website/geoipresolver.py b/addons/website/geoipresolver.py index 1f9b0e22724..e95b9318eb2 100644 --- a/addons/website/geoipresolver.py +++ b/addons/website/geoipresolver.py @@ -47,10 +47,14 @@ class GeoIPResolver(object): r = self._db.city(ip) except (ValueError, geoip2.errors.AddressNotFoundError): return {} + # Compatibility with Legacy database. + # Some ips cannot be located to a specific country. Legacy DB used to locate them in + # continent instead of country. Do the same to not change behavior of existing code. + country = r.country if r.country.geoname_id else r.continent return { 'city': r.city.name, - 'country_code': r.country.iso_code, - 'country_name': r.country.name, + 'country_code': country.iso_code, + 'country_name': country.name, 'region': r.subdivisions[0].iso_code if r.subdivisions else None, 'time_zone': r.location.time_zone, }