Skip to content

Commit

Permalink
Handle postcodesIO fail
Browse files Browse the repository at this point in the history
  • Loading branch information
janbaykara committed Dec 17, 2024
1 parent 05af2bb commit 239d071
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,9 +1811,13 @@ async def create_import_record(record):
sample_point = area.polygon.centroid

# get postcodeIO result for area.coordinates
postcode_data: PostcodesIOResult = await loaders[
"postcodesIOFromPoint"
].load(sample_point)
try:
postcode_data: PostcodesIOResult = await loaders[
"postcodesIOFromPoint"
].load(sample_point)
except Exception as e:
logger.error(f"Failed to get postcode data for {sample_point}: {e}")
postcode_data = None

steps.append({ "task": "postcode_from_area_coordinates", "service": Geocoder.POSTCODES_IO.value, "result": "failed" if postcode_data is None else "success" })

Expand Down
2 changes: 1 addition & 1 deletion hub/tests/test_external_data_source_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class TestMultiLevelGeocoding(TestCase):
"ward": "Tre-garth a Mynydd Llandygái",
"expected_area_type_code": "WD23", # TODO: actually a UTE
"expected_area_gss": "W05000107",
}
},
# A bunch of wards with the same name, should all point to different things
{
"id": "11",
Expand Down
2 changes: 1 addition & 1 deletion utils/postcodesIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def get_bulk_postcode_geo(postcodes) -> list[PostcodesIOResult]:


@async_batch_and_aggregate(settings.POSTCODES_IO_BATCH_MAXIMUM)
async def get_bulk_postcode_geo_from_coords(coordinates: list[Point], radius=500):
async def get_bulk_postcode_geo_from_coords(coordinates: list[Point], radius=150):
coords = [
{
"longitude": coord.x,
Expand Down

0 comments on commit 239d071

Please sign in to comment.