feat(csv-templates): Add CSV template validation endpoint and enhance error handling
- Introduced a new endpoint for validating CSV templates without saving, allowing users to check field mappings and type conversions. - Updated the `create_system_template` and `update_system_template` functions to include validation reports in responses. - Enhanced error handling in CSV import processes by integrating `enrich_row_error` for more informative error messages. - Improved the AdminCsvTemplateEditorPage to support format checking and display validation results, enhancing user experience. - Incremented version numbers for `csv_import` and `admin_csv_templates` to reflect these updates.
This commit is contained in:
1 parent
6945b748cb
commit
0629f88b37
10 files changed
+486
-39
No files matched your search
@@ -32,6 +32,7 @@ from csv_parser.core import (
|
||||
)
|
||||
from csv_parser.type_converter import build_row_after_mapping, diagnose_row_mapping
|
||||
from csv_parser.field_units import source_unit_choices_for_field
|
||||
from csv_parser.import_errors import enrich_row_error
|
||||
from csv_parser.module_registry import get_module_definition, list_modules, validate_field_mappings
|
||||
from csv_parser.sleep_apple_import import detect_apple_sleep_csv_format
|
||||
|
||||
@@ -554,6 +555,7 @@ async def csv_import_execute(
|
||||
except Exception as exec_err:
|
||||
logger.exception("Universal-CSV-Import fehlgeschlagen: %s", exec_err)
|
||||
cur.execute("ROLLBACK TO SAVEPOINT csv_import_exec")
|
||||
err_payload = {"error": str(exec_err), **enrich_row_error(str(exec_err), exec_module)}
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE csv_import_log SET
|
||||
@@ -562,9 +564,13 @@ async def csv_import_execute(
|
||||
error_details = %s
|
||||
WHERE id = %s
|
||||
""",
|
||||
(Json([{"error": str(exec_err)}]), log_id),
|
||||
(Json([err_payload]), log_id),
|
||||
)
|
||||
err_response = HTTPException(500, f"Import fehlgeschlagen: {exec_err}")
|
||||
hint = err_payload.get("hint")
|
||||
msg = f"Import fehlgeschlagen: {exec_err}"
|
||||
if hint:
|
||||
msg = f"{msg} ({hint})"
|
||||
err_response = HTTPException(500, msg)
|
||||
else:
|
||||
cur.execute("RELEASE SAVEPOINT csv_import_exec")
|
||||
cur.execute(
|
||||
|
||||
Reference in new issue
Block a user