Skip to content

Commit 600f34b

Browse files
committed
fix for area lookup error
1 parent fc5ee7f commit 600f34b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

findthatpostcode/blueprints/areas.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ def get_area_children_boundary(
7676
area = Area.get_from_es(areacode, es, boundary=False, examples_count=0)
7777
features = []
7878
errors = {}
79-
for child_area in area.relationships["children"][areatype]: # type: ignore
80-
result = Area.get_from_es(
81-
child_area.id, es, boundary=True, examples_count=0, s3_client=s3_client
82-
)
83-
status, r = result.geoJSON()
84-
if status == 200 and isinstance(r, dict):
85-
features.extend(r.get("features", []))
86-
else:
87-
errors[child_area.id] = r
79+
if area.relationships["children"]:
80+
for child_area in area.relationships["children"][areatype]: # type: ignore
81+
result = Area.get_from_es(
82+
child_area.id, es, boundary=True, examples_count=0, s3_client=s3_client
83+
)
84+
status, r = result.geoJSON()
85+
if status == 200 and isinstance(r, dict):
86+
features.extend(r.get("features", []))
87+
else:
88+
errors[child_area.id] = r
89+
else:
90+
errors["area"] = f"No children of type {areatype} found for area {areacode}"
8891
if not features:
8992
return JSONResponse(dict(message=errors), status_code=404)
9093
return {"type": "FeatureCollection", "features": features}

findthatpostcode/controllers/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def process_attributes(self: "Controller", data: dict) -> dict[str, object]:
6464

6565
@staticmethod
6666
def parse_id(id: str | tuple[float, float]) -> str | tuple[float, float]:
67-
return id
67+
return id.strip().upper() if isinstance(id, str) else id
6868

6969
@staticmethod
7070
def get_total_from_es(result: dict) -> int | None:

0 commit comments

Comments
 (0)