From 23ccfb0d0b865899e0df74a5782a41e15b97d895 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Tue, 23 Jun 2026 15:36:37 +0000 Subject: [PATCH] =?UTF-8?q?Skip=20a=20landlord=20override=20that=20targets?= =?UTF-8?q?=20a=20building=20part=20the=20EPC=20lacks=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Landlord Override can reference a building part the lodged or predicted EPC never carried (e.g. an extension_1 override on a property whose EPC has only main). apply_simulations indexed parts_by_id[identifier] unguarded, raising KeyError and aborting the whole property's modelling. Now the orphaned part is skipped. Recovers 14 of the 22 modelling_e2e failures in portfolio 796. Co-Authored-By: Claude Opus 4.8 (1M context) --- domain/modelling/scoring/overlay_applicator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/domain/modelling/scoring/overlay_applicator.py b/domain/modelling/scoring/overlay_applicator.py index 961f4e02..6a50fde4 100644 --- a/domain/modelling/scoring/overlay_applicator.py +++ b/domain/modelling/scoring/overlay_applicator.py @@ -41,7 +41,13 @@ def apply_simulations( for simulation in simulations: for identifier, overlay in simulation.building_parts.items(): - part = parts_by_id[identifier] + # A Landlord Override can target a building part the lodged (or + # predicted) EPC never carried — e.g. an `extension_1` override on a + # property whose EPC has only `main`. Skip the orphaned part rather + # than crashing the whole property's modelling on a `KeyError`. + part = parts_by_id.get(identifier) + if part is None: + continue for overlay_field in fields(overlay): value = getattr(overlay, overlay_field.name) if value is not None: