fix: Handle ValueError in accept_matches function for better error reporting
All checks were successful
CI / skip-ci-check (pull_request) Successful in 1m29s
CI / lint-and-type-check (pull_request) Successful in 2m6s
CI / python-lint (pull_request) Successful in 1m53s
CI / test-backend (pull_request) Successful in 3m12s
CI / build (pull_request) Successful in 2m47s
CI / secret-scanning (pull_request) Successful in 1m53s
CI / dependency-scan (pull_request) Successful in 1m36s
CI / sast-scan (pull_request) Successful in 2m45s
CI / workflow-summary (pull_request) Successful in 1m27s

This commit updates the `accept_matches` function in the `people.py` API to include error handling for `ValueError`. If the error message indicates that a resource is not found, it raises an HTTP 404 exception with a user-friendly message. This change improves the robustness of the API by providing clearer feedback to users when a match cannot be accepted.
This commit is contained in:
Tanya 2026-01-08 13:49:38 -05:00
parent 13f926b84e
commit 70cd7aad95
2 changed files with 11 additions and 4 deletions

View File

@ -486,7 +486,6 @@ jobs:
--no-banner \
--redact \
--verbose \
--platform git.levkin.ca \
--report-path gitleaks-report.json \
--exit-code 0
continue-on-error: true

View File

@ -266,9 +266,17 @@ def accept_matches(
from backend.api.auth import get_current_user_with_id
user_id = current_user["user_id"]
identified_count, updated_count = accept_auto_match_matches(
db, person_id, request.face_ids, user_id=user_id
)
try:
identified_count, updated_count = accept_auto_match_matches(
db, person_id, request.face_ids, user_id=user_id
)
except ValueError as e:
if "not found" in str(e).lower():
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=str(e)
)
raise
return IdentifyFaceResponse(
identified_face_ids=request.face_ids,