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