From 895e49df0457cb3507294ae9e428f5a730f7393d Mon Sep 17 00:00:00 2001 From: Natalia Borovskikh Date: Tue, 7 Jul 2026 13:22:02 +0000 Subject: [PATCH 1/2] Fix empty-band-list crash in get_rate_fixed_charge_at_dt when all bands are filtered by BOOLEAN applicability --- tariff_fetch/urdb/arcadia/fixedcharge.py | 5 ++- tests/test_arcadia_urdb_fixedcharge.py | 47 ++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/tariff_fetch/urdb/arcadia/fixedcharge.py b/tariff_fetch/urdb/arcadia/fixedcharge.py index 42f5e45..856c358 100644 --- a/tariff_fetch/urdb/arcadia/fixedcharge.py +++ b/tariff_fetch/urdb/arcadia/fixedcharge.py @@ -44,6 +44,7 @@ def get_fixed_charge_at_dt(scenario: Scenario, library: Library, dt: datetime) - master_tariff_id = scenario.master_tariff_id tariff = library.tariffs.get_tariff_at_date(master_tariff_id, dt.date()) rates = ru.tariff_iter_rates_for_dt(tariff, scenario, library, dt) + rates = list(rates) return sum(get_rate_fixed_charge_at_dt(scenario, library, rate, dt) for rate in rates) @@ -53,14 +54,14 @@ def get_rate_fixed_charge_at_dt(scenario: Scenario, library: Library, rate: Tari bands = ru.rate_filter_bands(rate, scenario, library) if rate["charge_type"] != "FIXED_PRICE": return 0 + if not bands: + return 0 if (variable_factor_key := rate.get("variable_factor_key")) is not None and not ( rate["charge_period"] == "MONTHLY" and variable_factor_key == "billingPeriodProrationFactor" ): raise RateConversionError(rate, "Fixed charges cannot have variable factors") if rate.get("quantity_key") is not None: raise RateConversionError(rate, "Rates with quantity_key are not supported for fixed charge conversion") - if not bands: - return 0 band_rate_units = {band["rate_unit"] for band in bands} if (transaction_type := rate["transaction_type"]) != "BUY": raise RateConversionError( diff --git a/tests/test_arcadia_urdb_fixedcharge.py b/tests/test_arcadia_urdb_fixedcharge.py index 5f419ca..5bf54b4 100644 --- a/tests/test_arcadia_urdb_fixedcharge.py +++ b/tests/test_arcadia_urdb_fixedcharge.py @@ -3,21 +3,60 @@ from tariff_fetch.arcadia.schema.tariff import TariffExtended from tariff_fetch.urdb.arcadia.exception import RateConversionError from tariff_fetch.urdb.arcadia.fixedcharge import build_fixed_charge -from tariff_fetch.urdb.arcadia.library import Library, TariffLibrary, VariablePropertyLibrary +from tariff_fetch.urdb.arcadia.library import Library, PropertyValue, TariffLibrary, VariablePropertyLibrary from tariff_fetch.urdb.arcadia.scenario import Scenario -from tests.arcadia_urdb_fixtures import BAND, RATE, TARIFF +from tests.arcadia_urdb_fixtures import BAND, PROPERTY, RATE, TARIFF -def make_stub_library(tariffs: list[TariffExtended]) -> Library: +def make_stub_library(tariffs: list[TariffExtended], properties: dict[str, PropertyValue] | None = None) -> Library: tariff_library = TariffLibrary(None, None, tariffs) variables_library = VariablePropertyLibrary(None, None, None) - return Library(None, None, None, tariff_library=tariff_library, variables_library=variables_library) + return Library(None, properties, None, tariff_library=tariff_library, variables_library=variables_library) def make_stub_scenario(tariff: TariffExtended) -> Scenario: return Scenario(tariff["master_tariff_id"], 2025, False) +def test_build_fixed_charge_inapplicable_bands_does_not_fail(): + tariff: TariffExtended = { + **TARIFF, + "rates": [ + { + **RATE, + "charge_type": "FIXED_PRICE", + "applicability_key": "APPLICABLE", + "charge_period": "MONTHLY", + "rate_bands": [ + { + **BAND, + "applicability_value": "true", + "rate_amount": 2.0, + } + ], + "quantity_key": "some_key", + } + ], + "properties": [ + { + "key_name": "APPLICABLE", + "display_name": "applicable", + "data_type": "BOOLEAN", + "operator": "=", + "keyspace": "tariff", + "family": "service", + "description": "applicability", + "property_types": "APPLICABILITY", + "is_default": False, + } + ], + } + scenario = make_stub_scenario(tariff) + library = make_stub_library([tariff], properties={"APPLICABLE": "false"}) + result = build_fixed_charge(scenario, library) + assert result.get("fixedchargefirstmeter") == 0 + + def test_build_fixed_charge_returns_zero_when_no_fixed_rates_apply(): tariff: TariffExtended = { **TARIFF, From 7fd7e4c3cb2c9695cf1a1e5b8d82e134f993357b Mon Sep 17 00:00:00 2001 From: Natalia Borovskikh Date: Tue, 7 Jul 2026 13:25:59 +0000 Subject: [PATCH 2/2] Fix formatting issue --- tests/test_arcadia_urdb_fixedcharge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_arcadia_urdb_fixedcharge.py b/tests/test_arcadia_urdb_fixedcharge.py index 5bf54b4..232f617 100644 --- a/tests/test_arcadia_urdb_fixedcharge.py +++ b/tests/test_arcadia_urdb_fixedcharge.py @@ -5,7 +5,7 @@ from tariff_fetch.urdb.arcadia.fixedcharge import build_fixed_charge from tariff_fetch.urdb.arcadia.library import Library, PropertyValue, TariffLibrary, VariablePropertyLibrary from tariff_fetch.urdb.arcadia.scenario import Scenario -from tests.arcadia_urdb_fixtures import BAND, PROPERTY, RATE, TARIFF +from tests.arcadia_urdb_fixtures import BAND, RATE, TARIFF def make_stub_library(tariffs: list[TariffExtended], properties: dict[str, PropertyValue] | None = None) -> Library: