diff --git a/applications/modelling_e2e/handler.py b/applications/modelling_e2e/handler.py index b4848f694..bf9ca8b06 100644 --- a/applications/modelling_e2e/handler.py +++ b/applications/modelling_e2e/handler.py @@ -512,12 +512,11 @@ def handler( # held-open read Session. (The ``finally`` is the safety net.) scenario = ScenarioPostgresRepository(read_session).get_many([scenario_id])[0] products = catalogue_snapshot_with_off_catalogue_overrides(read_session) + # Stored Solar is read whatever refetch_solar says — the flag decides + # whether a UPRN with no stored row gets a live Google fetch, never + # whether solar is modelled at all. stored_solar: dict[int, Optional[dict[str, Any]]] = ( - {} - if not refetch_solar - else SolarPostgresRepository(read_session).get_many( - list(set(uprns.values())) - ) + SolarPostgresRepository(read_session).get_many(list(set(uprns.values()))) ) epc_repo = EpcPostgresRepository(read_session) stored_lodged_epcs: dict[int, EpcPropertyData] = ( @@ -615,15 +614,16 @@ def handler( landlord_overrides=overrides, ).effective_epc - solar_insights: Optional[dict[str, Any]] + # refetch_solar gates ONLY the paid Google call for UPRNs with no + # stored row; stored insights always feed the Modelling stage. + # (False here once meant "no solar at all" — the pre-rename + # `no_solar` semantics — which silently stripped solar from every + # plan in a re-model batch.) + solar_insights: Optional[dict[str, Any]] = stored_solar.get(uprn) solar_was_fetched = False - if not refetch_solar: - solar_insights = None - else: - solar_insights = stored_solar.get(uprn) - if solar_insights is None: - solar_insights = _solar_insights_for(solar_client, spatial) - solar_was_fetched = solar_insights is not None + if solar_insights is None and refetch_solar: + solar_insights = _solar_insights_for(solar_client, spatial) + solar_was_fetched = solar_insights is not None plan = run_modelling( effective_epc,