Review nitpicks: pids_with_default naming, empty-batch guard, truthful fake 🟪

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 16:44:23 +00:00
parent 5c982beba4
commit 8dd125f199
3 changed files with 8 additions and 5 deletions

View file

@ -210,7 +210,7 @@ def _flush_writes(engine: Engine, writes: list[_PropertyWrite]) -> None:
# p.is_new rule — readers select one default Plan per property, so a
# first run under a non-default Scenario must still produce one).
# Also heals properties left default-less by runs before this rule.
have_default: set[int] = uow.plan.property_ids_with_default_plans(
pids_with_default: set[int] = uow.plan.property_ids_with_default_plans(
[w.property_id for w in writes]
)
plan_requests = [
@ -219,7 +219,7 @@ def _flush_writes(engine: Engine, writes: list[_PropertyWrite]) -> None:
property_id=w.property_id,
scenario_id=w.scenario_id,
portfolio_id=w.portfolio_id,
is_default=w.is_default or w.property_id not in have_default,
is_default=w.is_default or w.property_id not in pids_with_default,
)
for w in writes
]

View file

@ -47,6 +47,8 @@ class PlanPostgresRepository(PlanRepository):
)[0]
def property_ids_with_default_plans(self, property_ids: list[int]) -> set[int]:
if not property_ids:
return set()
rows = self._session.exec(
select(col(PlanModel.property_id))
.distinct()

View file

@ -212,6 +212,7 @@ class FakePlanRepository(PlanRepository):
def __init__(self) -> None:
self.saved: dict[tuple[int, int], Plan] = {}
self.default_property_ids: set[int] = set()
self._next_id = 1
def save(
@ -224,6 +225,8 @@ class FakePlanRepository(PlanRepository):
is_default: bool,
) -> int:
self.saved[(property_id, scenario_id)] = plan
if is_default:
self.default_property_ids.add(property_id)
plan_id = self._next_id
self._next_id += 1
return plan_id
@ -241,9 +244,7 @@ class FakePlanRepository(PlanRepository):
]
def property_ids_with_default_plans(self, property_ids: list[int]) -> set[int]:
# The fake store does not track defaults; every property reads as
# first-time (no default yet).
return set()
return self.default_property_ids.intersection(property_ids)
class _UnsetProductRepo(ProductRepository):