prefer-validated-uuid-comparison
Validate UUID identifiers at input boundaries before comparing them.
Why
Reparsing both operands while comparing identifiers moves input validation into business logic, repeats normalization and can raise on malformed input after the boundary has accepted it.
Fix
Parse and normalize UUIDs in the router's request schema or ingestion adapter, use the same nominal UUID-backed ID in domain and store contracts, then compare the typed values directly. Preserve canonicalization of existing string-backed data before removing constructors.
Examples
from uuid import UUID
def same_owner(item, request): return UUID(item.owner_id) == UUID(request.owner_id)from uuid import UUIDfrom typing import NewType
OwnerId = NewType("OwnerId", UUID)
def same_owner(current: OwnerId, requested: OwnerId) -> bool: return current == requested