refactor(csv_parser): Implement SAVEPOINT handling for activity import
- Added SAVEPOINT management to the `_import_activity` function to improve error handling during CSV imports. - Moved the training type resolution logic to occur within a transaction block, ensuring that errors can be rolled back without affecting the entire import process. - Enhanced error logging to capture evaluation failures, providing better insights during CSV import operations.
This commit is contained in:
parent
894ee1dd02
commit
08a2485f43
|
|
@ -872,13 +872,14 @@ def _import_activity(
|
||||||
dist = _sf_act(mapped.get("distance_km"))
|
dist = _sf_act(mapped.get("distance_km"))
|
||||||
|
|
||||||
wtype = str(activity_type).strip()
|
wtype = str(activity_type).strip()
|
||||||
training_type_id, training_category, training_subcategory = _resolve_training_type_for_activity(
|
|
||||||
cur, wtype, profile_id
|
|
||||||
)
|
|
||||||
|
|
||||||
iso = date_d.isoformat()
|
iso = date_d.isoformat()
|
||||||
|
|
||||||
|
# Pro Zeile: bei SQL-Fehler sonst „current transaction is aborted“ bis Xact-Ende.
|
||||||
|
cur.execute("SAVEPOINT csv_activity_row")
|
||||||
try:
|
try:
|
||||||
|
training_type_id, training_category, training_subcategory = _resolve_training_type_for_activity(
|
||||||
|
cur, wtype, profile_id
|
||||||
|
)
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
SELECT id FROM activity_log
|
SELECT id FROM activity_log
|
||||||
|
|
@ -986,7 +987,12 @@ def _import_activity(
|
||||||
_evaluate_and_save_activity(cur, aid, activity_dict, training_type_id, profile_id)
|
_evaluate_and_save_activity(cur, aid, activity_dict, training_type_id, profile_id)
|
||||||
except Exception as eval_err:
|
except Exception as eval_err:
|
||||||
logger.warning("[csv activity] Auto-Eval fehlgeschlagen: %s", eval_err)
|
logger.warning("[csv activity] Auto-Eval fehlgeschlagen: %s", eval_err)
|
||||||
|
cur.execute("RELEASE SAVEPOINT csv_activity_row")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
try:
|
||||||
|
cur.execute("ROLLBACK TO SAVEPOINT csv_activity_row")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
error_details.append({"row": rows_total, "error": str(e)})
|
error_details.append({"row": rows_total, "error": str(e)})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user