mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(prediction): update all providers before reporting a failing one
The prediction container stopped at the first enabled provider that failed to update, so the providers after it in the sequence were not updated in that run. A failing weather provider, at the start of the sequence, thus also kept the electricity price, feed-in tariff, load and PV forecasts from being updated. The container now updates all providers and then raises one RuntimeError with the failures of all enabled providers; with one failing provider the message is unchanged. Refs #1571 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
867bc38fc0
commit
c8f793c203
@@ -63,6 +63,27 @@ class DerivedDataProvider(DataProvider[DerivedRecord]):
|
||||
DerivedDataProvider.provider_updated = True
|
||||
|
||||
|
||||
class FailingDataProvider(DataProvider[DerivedRecord]):
|
||||
"""Enabled DataProvider whose update fails, like a remote API answering HTTP 500."""
|
||||
|
||||
records: List[DerivedRecord] = Field(
|
||||
default_factory=list, description="List of DerivedRecord records"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def record_class(cls) -> Any:
|
||||
return DerivedRecord
|
||||
|
||||
def provider_id(self) -> str:
|
||||
return "FailingDataProvider"
|
||||
|
||||
def enabled(self) -> bool:
|
||||
return True
|
||||
|
||||
async def _update_data(self, force_update: Optional[bool] = False) -> None:
|
||||
raise RuntimeError("500 Server Error")
|
||||
|
||||
|
||||
class DerivedDataContainer(DataContainer):
|
||||
providers: List[Union[DerivedDataProvider, DataProvider]] = Field(
|
||||
default_factory=list, description="List of data providers"
|
||||
@@ -260,6 +281,17 @@ class TestDataContainer:
|
||||
assert DerivedDataProvider.provider_updated is True
|
||||
DerivedDataProvider.provider_enabled = True # restore
|
||||
|
||||
async def test_update_data_failing_provider_does_not_skip_the_others(
|
||||
self, populated
|
||||
) -> None:
|
||||
"""A failing enabled provider is reported after all others were updated (#1571)."""
|
||||
populated.providers.insert(0, FailingDataProvider())
|
||||
DerivedDataProvider.provider_enabled = True
|
||||
DerivedDataProvider.provider_updated = False
|
||||
with pytest.raises(RuntimeError, match="Provider FailingDataProvider fails on update"):
|
||||
await populated.update_data()
|
||||
assert DerivedDataProvider.provider_updated is True
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# save / load
|
||||
# -----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user