Defensive coding

This commit is contained in:
Ian Renton
2026-07-26 07:57:48 +01:00
parent 77d7fd70d9
commit 3c1b1821f5
9 changed files with 19 additions and 18 deletions
+4 -3
View File
@@ -109,12 +109,13 @@ def populate_sig_ref_info(sig_ref):
# the zeroest corner of the box, then "lat2" and "lng2" provide the other corner. We detect this
# and provide a single lat/lon for the centre. Otherwise if we don't have these extra parameters,
# just use the single point we have.
if "latitude" in data and "longitude" in data and "lat2" in data and "lng2" in data:
if data.get("latitude") is not None and data.get("longitude") is not None and data.get(
"lat2") is not None and data.get("lng2") is not None:
sig_ref.latitude = (float(data["latitude"]) + float(data["lat2"])) / 2.0
sig_ref.longitude = (float(data["longitude"]) + float(data["lng2"])) / 2.0
else:
sig_ref.latitude = float(data["latitude"]) if "latitude" in data else None
sig_ref.longitude = float(data["longitude"]) if "longitude" in data else None
sig_ref.latitude = float(data["latitude"]) if data.get("latitude") is not None else None
sig_ref.longitude = float(data["longitude"]) if data.get("longitude") is not None else None
elif not response.from_cache:
logging.warning("Malformed response looking up %s ref %s via GMA", sig, ref_id)
elif not response.from_cache: