Enhance V3 CRUD: Implement Error Bubbling and Dry-Run Validation.
- Updated app/db_sql.py to capture SQL exceptions in thread-local storage for later retrieval.
- Implemented format_db_error() in app/lib_api_crud_v3.py to clean up raw MariaDB error strings.
- Added POST /v3/crud/{obj_type}/validate endpoint for dry-run payload validation.
- Updated main and nested routers to bubble up validation and database errors into the response 'meta.details' field.
- Added tests/test_v3_error_bubbling.py to verify formatting logic.
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
from typing import Any, Dict, Optional
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
||||
from app.lib_general_v3 import AccountContext, StatusFilterParams
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def format_db_error(raw_error: str) -> str:
|
||||
"""
|
||||
Parses raw SQLAlchemy/MariaDB errors into user-friendly strings.
|
||||
"""
|
||||
if not raw_error:
|
||||
return ""
|
||||
|
||||
# Standard MariaDB pattern: (code, "message")
|
||||
match = re.search(r'\(\d+,\s*["\'](.*?)["\']\s*\)', raw_error)
|
||||
if match:
|
||||
return match.group(1).strip()
|
||||
|
||||
# Fallback: remove all (parenthesized) blocks which often contain codes
|
||||
clean = re.sub(r'\(.*?\)', '', raw_error)
|
||||
return clean.strip()
|
||||
|
||||
def check_account_access(sql_result: Any, account: AccountContext, obj_name: str = None) -> bool:
|
||||
"""
|
||||
Enforce Multi-Tenant Data Isolation.
|
||||
|
||||
Reference in New Issue
Block a user