From c51ca47467e3bca33f2ef2c140300075c86cc6f1 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Fri, 26 Jun 2026 10:12:21 +0000 Subject: [PATCH] =?UTF-8?q?Rename=20no=5Fsolar=20=E2=86=92=20refetch=5Fsol?= =?UTF-8?q?ar=20and=20add=20refetch=5Fepc,=20repredict=5Fepc=20flags=20to?= =?UTF-8?q?=20TriggerBody=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- applications/modelling_e2e/handler.py | 11 ++++--- .../modelling_e2e_trigger_body.py | 4 ++- .../modelling_e2e/test_handler.py | 29 +++++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/applications/modelling_e2e/handler.py b/applications/modelling_e2e/handler.py index 5b3db070..7ae15bef 100644 --- a/applications/modelling_e2e/handler.py +++ b/applications/modelling_e2e/handler.py @@ -412,12 +412,15 @@ def handler(body: dict[str, Any], context: Any, orchestrator: TaskOrchestrator, property_ids = trigger.property_ids portfolio_id = trigger.portfolio_id scenario_id = trigger.scenario_id - no_solar = trigger.no_solar + refetch_solar = trigger.refetch_solar + refetch_epc = trigger.refetch_epc + repredict_epc = trigger.repredict_epc dry_run = trigger.dry_run logger.info( f"start property_ids={property_ids} portfolio={portfolio_id} " - f"scenario={scenario_id} no_solar={no_solar} dry_run={dry_run}" + f"scenario={scenario_id} refetch_solar={refetch_solar} " + f"refetch_epc={refetch_epc} repredict_epc={repredict_epc} dry_run={dry_run}" ) engine = _get_engine() @@ -499,7 +502,7 @@ def handler(body: dict[str, Any], context: Any, orchestrator: TaskOrchestrator, products = catalogue_snapshot_with_off_catalogue_overrides(read_session) stored_solar: dict[int, Optional[dict[str, Any]]] = ( {} - if no_solar + if not refetch_solar else SolarPostgresRepository(read_session).get_many( list(set(uprns.values())) ) @@ -573,7 +576,7 @@ def handler(body: dict[str, Any], context: Any, orchestrator: TaskOrchestrator, solar_insights: Optional[dict[str, Any]] solar_was_fetched = False - if no_solar: + if not refetch_solar: solar_insights = None else: solar_insights = stored_solar.get(uprn) diff --git a/applications/modelling_e2e/modelling_e2e_trigger_body.py b/applications/modelling_e2e/modelling_e2e_trigger_body.py index cb83118a..f9c92513 100644 --- a/applications/modelling_e2e/modelling_e2e_trigger_body.py +++ b/applications/modelling_e2e/modelling_e2e_trigger_body.py @@ -7,5 +7,7 @@ class ModellingE2ETriggerBody(BaseModel): property_ids: list[int] portfolio_id: int scenario_id: int - no_solar: bool = False + refetch_solar: bool = True + refetch_epc: bool = True + repredict_epc: bool = True dry_run: bool = False diff --git a/tests/applications/modelling_e2e/test_handler.py b/tests/applications/modelling_e2e/test_handler.py index 7f11c7d7..6ee7fb13 100644 --- a/tests/applications/modelling_e2e/test_handler.py +++ b/tests/applications/modelling_e2e/test_handler.py @@ -36,7 +36,7 @@ _BODY = { "property_ids": [PROPERTY_ID], "portfolio_id": PORTFOLIO_ID, "scenario_id": SCENARIO_ID, - "no_solar": True, + "refetch_solar": False, "dry_run": False, } @@ -188,6 +188,25 @@ def test_trigger_body_rejects_missing_property_ids() -> None: ) +def test_trigger_body_new_flags_default_to_true() -> None: + """refetch_epc, repredict_epc, and refetch_solar all default True so that + existing callers that omit them get current behaviour (live fetches).""" + # Arrange + body = { + "property_ids": [PROPERTY_ID], + "portfolio_id": PORTFOLIO_ID, + "scenario_id": SCENARIO_ID, + } + + # Act + result = ModellingE2ETriggerBody.model_validate(body) + + # Assert + assert result.refetch_epc is True + assert result.repredict_epc is True + assert result.refetch_solar is True + + # --------------------------------------------------------------------------- # Child SubTask creation # --------------------------------------------------------------------------- @@ -243,7 +262,7 @@ def test_handler_creates_one_child_subtask_per_property_id() -> None: from applications.modelling_e2e.handler import handler handler.__wrapped__( # type: ignore[attr-defined] {"property_ids": [pid1, pid2, pid3], "portfolio_id": PORTFOLIO_ID, - "scenario_id": SCENARIO_ID, "no_solar": True, "dry_run": False}, + "scenario_id": SCENARIO_ID, "refetch_solar": False, "dry_run": False}, None, mock_orch, task_id, ) @@ -896,7 +915,7 @@ def test_per_property_failure_fails_child_subtask_and_siblings_continue() -> Non # Act — must not raise even though pid2 fails _call_handler( {"property_ids": [pid1, pid2], "portfolio_id": PORTFOLIO_ID, - "scenario_id": SCENARIO_ID, "no_solar": True, "dry_run": False}, + "scenario_id": SCENARIO_ID, "refetch_solar": False, "dry_run": False}, orchestrator=mock_orch, ) @@ -962,7 +981,7 @@ def test_batch_persists_in_one_transaction_and_one_baseline_run( # Act _call_handler( {"property_ids": [pid1, pid2, pid3], "portfolio_id": PORTFOLIO_ID, - "scenario_id": SCENARIO_ID, "no_solar": True, "dry_run": False} + "scenario_id": SCENARIO_ID, "refetch_solar": False, "dry_run": False} ) # Assert — all three Plans saved, but a single shared transaction: @@ -1079,7 +1098,7 @@ def test_cohort_cache_prevents_duplicate_candidates_for_calls() -> None: "property_ids": [pid1, pid2], "portfolio_id": PORTFOLIO_ID, "scenario_id": SCENARIO_ID, - "no_solar": True, + "refetch_solar": False, "dry_run": False, } )