diff --git a/applications/modelling_e2e/handler.py b/applications/modelling_e2e/handler.py index b580a37d4..55a646676 100644 --- a/applications/modelling_e2e/handler.py +++ b/applications/modelling_e2e/handler.py @@ -205,13 +205,21 @@ def _flush_writes(engine: Engine, writes: list[_PropertyWrite]) -> None: uow.epc.save_batch(lodged_requests) if predicted_requests: uow.epc.save_batch(predicted_requests) + # First plan wins: a property with no default Plan yet gets this Plan + # as its default whatever the Scenario's flag says (the legacy + # p.is_new rule — readers select one default Plan per property, so a + # first run under a non-default Scenario must still produce one). + # Also heals properties left default-less by runs before this rule. + have_default: set[int] = uow.plan.property_ids_with_default_plans( + [w.property_id for w in writes] + ) plan_requests = [ PlanSaveRequest( w.plan, property_id=w.property_id, scenario_id=w.scenario_id, portfolio_id=w.portfolio_id, - is_default=w.is_default, + is_default=w.is_default or w.property_id not in have_default, ) for w in writes ]