refactor(csv_parser): Update training type resolution to use existing database cursor
Deploy Development / deploy (push) Successful in 48s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Modified `_resolve_training_type_for_activity` to accept a database cursor, improving efficiency and avoiding potential deadlocks during CSV imports.
- Introduced `get_training_type_for_activity_with_cursor` to handle training type resolution with an existing cursor, streamlining database interactions.
- Updated related calls in the activity import logic to utilize the new function, ensuring consistent behavior across the application.
This commit is contained in:
Lars committed 2026-04-11 06:27:11 +02:00
1 parent a9bd3faabb
commit 894ee1dd02
3 files changed
+52 -32

No files matched your search

+5 -5
View File
@@ -31,11 +31,11 @@ except Exception: # pragma: no cover
_EVALUATION_AVAILABLE = False
def _resolve_training_type_for_activity(activity_type: str, profile_id: str):
"""Lazy import — ermöglicht Tests ohne Laden von routers.activity (bcrypt)."""
from routers.activity import get_training_type_for_activity
def _resolve_training_type_for_activity(cur, activity_type: str, profile_id: str):
"""Lazy import — gleicher DB-Cursor wie der Import (kein verschachteltes get_db / Pool-Deadlock)."""
from routers.activity import get_training_type_for_activity_with_cursor
return get_training_type_for_activity(activity_type, profile_id)
return get_training_type_for_activity_with_cursor(cur, activity_type, profile_id)
def coerce_date(val: Any) -> dt.date | None:
@@ -873,7 +873,7 @@ def _import_activity(
wtype = str(activity_type).strip()
training_type_id, training_category, training_subcategory = _resolve_training_type_for_activity(
wtype, profile_id
cur, wtype, profile_id
)
iso = date_d.isoformat()