diff --git a/repositories/property/landlord_address_resolver.py b/repositories/property/landlord_address_resolver.py index 332f6b149..cf051c0bd 100644 --- a/repositories/property/landlord_address_resolver.py +++ b/repositories/property/landlord_address_resolver.py @@ -23,8 +23,15 @@ class LandlordAddressResolver: def __init__( self, session: Session, landlord_property_ids: Sequence[str] ) -> None: - self._session = session - self._ids = list(landlord_property_ids) + stmt = select(PropertyRow).where( + col(PropertyRow.landlord_property_id).in_(list(landlord_property_ids)) + ) + rows = session.execute(stmt).scalars().all() # pyright: ignore[reportDeprecated] + self._by_id: dict[str, str] = { + row.landlord_property_id: row.address + for row in rows + if row.landlord_property_id is not None and row.address is not None + } def address_for(self, landlord_property_id: str) -> str: - raise NotImplementedError + return self._by_id.get(landlord_property_id, self._FALLBACK)