From d89983d44f5fd9383aa61e5d8e73a548e94a58e2 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 1 Jun 2026 14:58:11 +0000 Subject: [PATCH] refactor(property): PropertyRow.id non-Optional (PR #1139 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `property` is an FE-owned table the backend only ever reads — every row read carries an id — so the autoincrement-PK `Optional[int]` idiom doesn't apply here. Make it `int` and drop the now-redundant None guard in get_many. (Contrast: solar_table keeps Optional id — the backend DOES insert those, so id is genuinely None pre-flush.) Co-Authored-By: Claude Opus 4.8 --- infrastructure/postgres/property_table.py | 4 +++- repositories/property/property_postgres_repository.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/infrastructure/postgres/property_table.py b/infrastructure/postgres/property_table.py index 0b91a2ad..6bd2d644 100644 --- a/infrastructure/postgres/property_table.py +++ b/infrastructure/postgres/property_table.py @@ -15,7 +15,9 @@ class PropertyRow(SQLModel, table=True): __tablename__: ClassVar[str] = "property" # pyright: ignore[reportIncompatibleVariableOverride] - id: Optional[int] = Field(default=None, primary_key=True) + # Non-Optional: this is a read-only defensive view of the FE-owned ``property`` + # table — the backend never inserts rows, so every row read carries an id. + id: int = Field(primary_key=True) portfolio_id: int postcode: str address: str diff --git a/repositories/property/property_postgres_repository.py b/repositories/property/property_postgres_repository.py index e0b4f9ff..55a32ed3 100644 --- a/repositories/property/property_postgres_repository.py +++ b/repositories/property/property_postgres_repository.py @@ -42,7 +42,7 @@ class PropertyPostgresRepository(PropertyRepository): rows = self._session.exec( select(PropertyRow).where(col(PropertyRow.id).in_(property_ids)) ).all() - row_by_id = {row.id: row for row in rows if row.id is not None} + row_by_id = {row.id: row for row in rows} epcs = self._epc_repo.get_for_properties(property_ids) items: list[Property] = [] for property_id in property_ids: