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
@@ -6,6 +6,7 @@ from uuid import UUID
import aiosqlite
from app.entities.user import User
from app.repositories.filter_validator import validate_filters
from app.repositories.user_repository import UserRepository
from app.utils.errors import NotFoundError
@@ -72,6 +73,7 @@ class SQLiteUserRepository(UserRepository):
raise NotFoundError(f"User {id} not found")
async def list(self, **filters: object) -> list[User]:
validate_filters(filters, set())
cursor = await self._conn.execute('SELECT * FROM "user"')
rows = await cursor.fetchall()
return [self._row_to_entity(r) for r in rows]