from db import db def disable_trigger(table: str, trigger: str): """ Decorator for disabling triggers for specific tables while function executed. Args: function: table: trigger: """ def decorator_func(func): def wrapper_func(*args, **kwargs): db.session.execute(f""" ALTER TABLE "{table}" DISABLE TRIGGER {trigger}; """) retval = func(*args, **kwargs) db.session.execute(f""" ALTER TABLE "{table}" ENABLE TRIGGER {trigger}; """) db.session.commit() return retval return wrapper_func return decorator_func