From f9f80f7184c30abc514b740afeeb7d2a0d33c6ad Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 6 Jul 2026 08:17:54 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20a=20UPRN=20to=20its=20historic=20EPC?= =?UTF-8?q?=20record=20by=20exact=20match=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- repositories/historic_epc/historic_epc_resolver.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repositories/historic_epc/historic_epc_resolver.py b/repositories/historic_epc/historic_epc_resolver.py index 823db3c38..21a7457be 100644 --- a/repositories/historic_epc/historic_epc_resolver.py +++ b/repositories/historic_epc/historic_epc_resolver.py @@ -35,8 +35,17 @@ class HistoricEpcResolver: ) def record_for_uprn(self, uprn: str, postcode: str) -> Optional[HistoricEpc]: - """The postcode shard's certificate for ``uprn``, or None.""" - return None + """The postcode shard's certificate for ``uprn``, or None on a miss. + + Exact UPRN equality only — the prediction path must never import a + fuzzy address match's attributes as if observed (ADR-0054).""" + if not uprn: + return None + records: list[HistoricEpc] = self._repo.get_for_postcode(Postcode(postcode)) + certs: list[HistoricEpc] = [r for r in records if r.uprn == uprn] + if not certs: + return None + return max(certs, key=lambda r: r.lodgement_date) def resolve_uprn( self, user_address: str, postcode: str