fixed cloud logs error

This commit is contained in:
Khalim Conn-Kowlessar 2025-11-28 08:03:37 +00:00
parent e29e96e617
commit 54b472dd47
2 changed files with 22 additions and 4 deletions

View file

@ -40,6 +40,9 @@ def get_associated_uprns(session: Session, postcode: str, uprn: str):
.filter(func.upper(PostcodeSearch.postcode) == postcode)
.first()
)
if not record:
# No record found for this postcode
return []
matched_record = _get_associated_records(results=record.result_data["results"], uprn=uprn)

View file

@ -449,6 +449,10 @@ async def model_engine(body: PlanTriggerRequest):
plan_input["built_form"] = plan_input["landlord_built_form"].copy()
else:
plan_input["built_form"] = None
if "epc_property_type" not in plan_input.columns:
plan_input["epc_property_type"] = None
plan_input["property_type"] = np.where(
plan_input["property_type"] == "unknown",
plan_input["epc_property_type"],
@ -468,7 +472,7 @@ async def model_engine(body: PlanTriggerRequest):
"bungalow": "Bungalow",
"block house": "House",
"coach house": "House",
"bedsit": "Flat"
"bedsit": "Flat",
}
built_form_map = {
@ -480,8 +484,19 @@ async def model_engine(body: PlanTriggerRequest):
"enclosed mid-terrace": "Enclosed Mid-Terrace",
}
# We remap the values to match the EPC expected formats
plan_input["property_type"] = plan_input["property_type"].map(property_type_map)
plan_input["built_form"] = plan_input["built_form"].map(built_form_map)
# This syntax will actually retain any original values, if they don't get mapped
plan_input["property_type"] = (
plan_input["property_type"]
.map(property_type_map)
.fillna(plan_input["property_type"])
)
plan_input["built_form"] = (
plan_input["built_form"]
.map(built_form_map)
.fillna(plan_input["built_form"])
)
plan_input = plan_input.to_dict("records")
@ -669,7 +684,7 @@ async def model_engine(body: PlanTriggerRequest):
address=epc_searcher.address_clean,
postcode=epc_searcher.postcode_clean,
epc_record=prepared_epc,
already_installed=req_data.already_installed + eco_packages[property_id][3],
already_installed=req_data.already_installed + eco_packages.get(property_id)[3],
property_valuation=req_data.valuation,
non_invasive_recommendations=property_non_invasive_recommendations,
energy_assessment=energy_assessment,