Model/repositories/property
Jun-te Kim de71f9abb6 Resolve overrides on the unit's own session, not a second connection
The modelling_e2e Lambda runs on a single-connection pool (pool_size=1,
max_overflow=0) so one invocation uses one Postgres connection. But re-hydrating
a Property through PostgresUnitOfWork resolved its Landlord Overrides through a
PropertyOverridesPostgresReader built from the unit's session *factory* — which
opens a brand-new Session per call. While the unit's own read transaction was
still open (PropertyPostgresRepository.get_many had checked out the connection),
that second Session asked the pool for a second connection, found none, and timed
out after 30s:

  QueuePool limit of size 1 overflow 0 reached, connection timed out, timeout 30.00

The baseline stage (PropertyBaselineOrchestrator.run -> uow.property.get_many ->
landlord overrides) hit this on every invocation.

Read the overrides on the unit's OWN session instead. property_overrides is
committed reference data, so reading it inside the unit's transaction sees the
same rows and keeps the invocation on one connection. Extract the query/mapping
into a shared helper and add OpenSessionPropertyOverridesReader (reads on a
caller-owned, already-open session without closing it) for the unit; the
standalone PropertyOverridesPostgresReader still opens its own short session for
use outside a unit.

Regression test pins the invariant with a real pool_size=1/max_overflow=0 engine:
without the fix it reproduces the exact QueuePool timeout.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 17:01:41 +00:00
..
__init__.py feat(property): Property aggregate + PropertyRepository (#1132) 2026-05-30 19:39:54 +00:00
in_memory_property_overrides_reader.py Hold one DB connection per modelling_e2e invocation 2026-06-24 16:58:21 +00:00
landlord_override_overlays.py landlord override data added 2026-06-20 12:57:54 +00:00
override_backed_prediction_attributes_reader.py Group landlord property-override enums under domain/epc/property_overrides 🟪 2026-06-19 14:49:58 +00:00
prediction_target_attributes_reader.py feat(epc-prediction): slice-5d target assembly + eligibility gate 2026-06-16 03:56:57 +00:00
property_override_postgres_repository.py property override 2026-06-05 12:18:13 +00:00
property_override_repository.py property override 2026-06-05 12:18:13 +00:00
property_overrides_postgres_reader.py Resolve overrides on the unit's own session, not a second connection 2026-06-24 17:01:41 +00:00
property_overrides_reader.py Read a Property's resolved landlord overrides as a faithful value-space snapshot 🟩 2026-06-16 15:14:53 +00:00
property_postgres_repository.py Merge branch 'main' of https://github.com/Hestia-Homes/Model into feature/landlord-overrides 2026-06-17 08:50:52 +00:00
property_repository.py feat(modelling): mark a Property as run via has_recommendations + updated_at 2026-06-16 23:34:33 +00:00