Rename no_solar → refetch_solar and add refetch_epc, repredict_epc flags to TriggerBody 🟩

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-06-26 10:12:21 +00:00
parent 04b3cb240a
commit c51ca47467
3 changed files with 34 additions and 10 deletions

View file

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

View file

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

View file

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