refetch_solar=False models with stored Solar insights and never calls Google 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-07-02 14:21:46 +00:00
parent c1a558d2b5
commit 100949073f

View file

@ -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,