MCPcopy Create free account
hub / github.com/dataease/SQLBot / sync_wrapper

Function sync_wrapper

backend/common/audit/schemas/logger_decorator.py:597–688  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

595
596 @functools.wraps(func)
597 def sync_wrapper(*args, **kwargs):
598 start_time = time.time()
599 status = OperationStatus.SUCCESS
600 error_message = None
601 request = None
602 resource_id = None
603 resource_name = None
604 resource_info_list = None
605 result = None
606
607 try:
608 # Get current request
609 request = RequestContext.get_request()
610 func_signature = inspect.signature(func)
611 bound_args = func_signature.bind(*args, **kwargs)
612 bound_args.apply_defaults()
613 unified_kwargs = dict(bound_args.arguments)
614
615 # Extract resource ID from parameters
616 if config.resource_id_expr:
617 resource_id = SystemLogger.extract_from_function_params(
618 config.resource_id_expr,
619 unified_kwargs,
620 kwargs
621 )
622
623 # Obtain client information
624 if config.operation_type == OperationType.DELETE:
625 with Session(engine) as session:
626 resource_info_list = get_resource_name_by_id_and_module(session, resource_id, config.module)
627
628 # Execute the original function
629 result = func(*args, **kwargs)
630
631 # Extract resource ID from the results
632 if config.result_id_expr and not resource_id and result:
633 resource_id = SystemLogger.extract_resource_id(
634 config.result_id_expr,
635 result,
636 "result"
637 )
638
639 return result
640
641 except Exception as e:
642 status = OperationStatus.FAILED
643 error_message = str(e)
644
645 if isinstance(e, HTTPException):
646 error_message = f"HTTP {e.status_code}: {e.detail}"
647
648 if config.ignore_errors:
649 status = OperationStatus.SUCCESS
650
651 raise e
652
653 finally:
654 if config.save_on_success_only and status == OperationStatus.FAILED:

Callers

nothing calls this directly

Calls 8

extract_resource_idMethod · 0.80
is_runningMethod · 0.80
create_log_recordMethod · 0.80
runMethod · 0.80
get_requestMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected