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:
@@ -7,6 +7,7 @@ import aiosqlite
|
||||
|
||||
from app.entities.child import Child
|
||||
from app.repositories.child_repository import ChildRepository
|
||||
from app.repositories.filter_validator import validate_filters
|
||||
from app.utils.errors import NotFoundError
|
||||
|
||||
|
||||
@@ -87,6 +88,7 @@ class SQLiteChildRepository(ChildRepository):
|
||||
raise NotFoundError(f"Child {id} not found")
|
||||
|
||||
async def list(self, **filters: object) -> list[Child]:
|
||||
validate_filters(filters, {"workspace_id"})
|
||||
clauses: list[str] = []
|
||||
params: list[object] = []
|
||||
if "workspace_id" in filters and filters["workspace_id"] is not None:
|
||||
|
||||
Reference in New Issue
Block a user