Merge pull request #1300 from Hestia-Homes/feature/notnullviolation-optional-fields-21-0-1

fix: coalesce omitted 21.0.1 optional count fields to 0 to prevent NotNullViolation on persist
This commit is contained in:
Daniel Roth 2026-06-24 14:36:04 +01:00 committed by GitHub
commit f6e5e11d88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 4 deletions

View file

@ -2172,7 +2172,7 @@ class EpcPropertyDataMapper:
# to 0 like every other mapper (RdSAP "not lodged" → calc minimum 1).
wet_rooms_count=schema.wet_rooms_count or 0,
extensions_count=schema.extensions_count,
open_chimneys_count=schema.open_chimneys_count,
open_chimneys_count=schema.open_chimneys_count or 0,
insulated_door_count=schema.insulated_door_count,
draughtproofed_door_count=schema.draughtproofed_door_count,
# Mechanical ventilation PCDB plumbing — feeds the §5 Table 4f
@ -2188,8 +2188,8 @@ class EpcPropertyDataMapper:
),
mechanical_vent_duct_type=schema.mechanical_vent_duct_type,
# Lighting
led_fixed_lighting_bulbs_count=schema.led_fixed_lighting_bulbs_count,
cfl_fixed_lighting_bulbs_count=schema.cfl_fixed_lighting_bulbs_count,
led_fixed_lighting_bulbs_count=schema.led_fixed_lighting_bulbs_count or 0,
cfl_fixed_lighting_bulbs_count=schema.cfl_fixed_lighting_bulbs_count or 0,
incandescent_fixed_lighting_bulbs_count=schema.incandescent_fixed_lighting_bulbs_count,
# Energy elements
roofs=EpcPropertyDataMapper._map_energy_elements(schema.roofs),

View file

@ -431,6 +431,33 @@ class TestFromRdSapSchema21_0_1:
assert result.wet_rooms_count == 0
def test_omitted_open_chimneys_count_defaults_to_zero_not_none(self) -> None:
data = load("21_0_1.json")
data.pop("open_chimneys_count", None)
schema = from_dict(RdSapSchema21_0_1, data)
result = EpcPropertyDataMapper.from_rdsap_schema_21_0_1(schema)
assert result.open_chimneys_count == 0
def test_omitted_cfl_fixed_lighting_bulbs_count_defaults_to_zero_not_none(self) -> None:
data = load("21_0_1.json")
data.pop("cfl_fixed_lighting_bulbs_count", None)
schema = from_dict(RdSapSchema21_0_1, data)
result = EpcPropertyDataMapper.from_rdsap_schema_21_0_1(schema)
assert result.cfl_fixed_lighting_bulbs_count == 0
def test_omitted_led_fixed_lighting_bulbs_count_defaults_to_zero_not_none(self) -> None:
data = load("21_0_1.json")
data.pop("led_fixed_lighting_bulbs_count", None)
schema = from_dict(RdSapSchema21_0_1, data)
result = EpcPropertyDataMapper.from_rdsap_schema_21_0_1(schema)
assert result.led_fixed_lighting_bulbs_count == 0
def test_uprn(self, result: EpcPropertyData) -> None:
assert result.uprn == 12457

View file

@ -179,7 +179,7 @@ def test_few_measure_cert_surfaces_only_its_fired_measures_triggers() -> None:
}
assert triggers["low_energy_lighting"].triggers == {
"incandescent_fixed_lighting_bulbs_count": 0,
"cfl_fixed_lighting_bulbs_count": None,
"cfl_fixed_lighting_bulbs_count": 0,
"low_energy_fixed_lighting_bulbs_count": 7,
}