Make repository list() reject unrecognised filter names

Repository.list(**filters) let each implementation pick out the filter
names it understood and silently ignore the rest, so a typo or an
unsupported filter returned every row in the table instead of an error.

This was hit for real: LeaveWishRepository.list(parent_personal_data_uuid
=...) returns every wish in the database, because that implementation
only recognises workspace_id and child_id. A guard written on top of it
would have passed while checking nothing.

All ten implementations now validate against their supported set and
raise ValueError naming the offending key. ValueError rather than a
domain error because passing a filter that does not exist is a
programming bug to fix, not a runtime condition to handle -- it must not
become an HTTP 4xx.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
2026-09-14 18:54:34 +02:00
parent 8ebfcb9462
commit 68d982bb94
14 changed files with 151 additions and 3 deletions
@@ -7,6 +7,7 @@ All methods raise NotImplementedError until then.
from uuid import UUID
from app.entities.vacation_days import VacationDays
from app.repositories.filter_validator import validate_filters
from app.repositories.vacation_days_repository import VacationDaysRepository
@@ -27,6 +28,7 @@ class PostgresVacationDaysRepository(VacationDaysRepository):
raise NotImplementedError("Postgres repo not yet implemented")
async def list(self, **filters: object) -> list[VacationDays]:
validate_filters(filters, {"workspace_id", "personal_data_uuid", "year"})
raise NotImplementedError("Postgres repo not yet implemented")
async def get_by_parent_year(self, personal_data_uuid: UUID, year: int) -> VacationDays | None: